AJAX请求得到时会发生什么" 302&搬迁QUOT;响应? [英] What happens when an AJAX request gets a "302 Moved" response?

查看:152
本文介绍了AJAX请求得到时会发生什么" 302&搬迁QUOT;响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想不修改后端AJAXify旧网站的形式。本来,后端将响应以感动302接收后的形式重定向到一个谢谢你页面。

I'm trying to AJAXify an old website form without modifying the back end. Originally, the backend would response with a "302 Moved" redirect to a "thank you" page after receiving the form.

现在,当我尝试使用jQuery的$就调用提交表单,表单数据被成功提交,但感动302重定向似乎得到由浏览器取消和jQuery不知道是怎么回事

Now, when I try to submit the form using a jQuery $.ajax call, the form data gets submitted successfully, but the "302 Moved" redirect seems to get cancelled by the browser and jQuery doesn't know what's going on.

我的问题是,无论发生什么情况,$就调用返回的错误和状态= 0,所以我没有办法成功的区分提交和错误。

My problem is that no matter what happens, the $.ajax call returns with an error and status = 0, so I have no way to distinguish between a successful submit and an error.

有没有一种方法,以prevent从试图跟随重定向,或至少找回了正确的响应codeS的浏览器? (我使用的浏览器。)

Is there a way to prevent the browser from trying to follow the redirect, or at least getting back the proper response codes? (I'm using Chrome.)

推荐答案

我觉得没什么,你不能做到这一点不改变背end.You已经改变响应头,为Ajax知道/了解什么do.If你犯了一个重定向,你必须改变标题,因为Ajax调用的响应不会去做。

I think no,you can't do it without changing the back-end.You have to change the response header,for Ajax to know/understand what to do.If you made a redirect,you have to change the header,because Ajax call response will not do it.

这篇关于AJAX请求得到时会发生什么" 302&搬迁QUOT;响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆