Home  >  Article  >  Backend Development  >  Reasons why response redirection does not work after initiating an ajax request

Reasons why response redirection does not work after initiating an ajax request

零到壹度
零到壹度Original
2018-04-10 09:47:554408browse

The content shared with you in this article is the reason why the response redirection does not work after initiating an ajax request. It has a certain reference value. Friends in need can refer to it

<br>

Summary:

Ajax只是利用脚本访问对应url获取数据而已,不能做除了获取返回数据以外的其它动作了。所以浏览器端是不会发起重定向的。
<br>
个人理解正常http url请求和ajax请求的区别:
1)正常的http url请求,只有浏览器和服务器两个参与者。浏览器端发起一个http请求,服务器端处理后发起一个重定向,浏览器端从response中获取到重定向地址,发起另一个http url请求。也就是说,浏览器会按照response中的内容进行响应(如重定向),这是浏览器的功能决定的就得响应。
2)Ajax请求,参与者就有三个即ajax、客户端、服务器,ajax处于客户端和服务器两者之间。过程是客户端发起一个ajax请求,服务器端处理后,如果发起一个重定向,然后ajax会怎么办呢?它只会获取刚才请求返回的数据,其他的任何动作一概不去做,ajax是这么做的(ajax功能就是这么设定的,ajax框架源代码也是这么写的)。
<br>
也就是说,引入了ajax之后,ajax就插在浏览器和服务器之间了,服务器给浏览器的response被ajax拦截了,但是ajax本身却什么都不做,也不转达。
<br>
<br>

In other words, if you want to implement redirection, you have to code it yourself. , that is, transform ajax. Reference: http://blog.csdn.net/ideality_hunter/article/details/61620875

The above is the detailed content of Reasons why response redirection does not work after initiating an ajax request. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn