简体   繁体   English

jQuery表单插件:如何正确处理从服务器发送回的重定向请求

[英]jquery form plugin : how to correctly handle a redirect request sent back from the server

I am using the jquery ajax plugin to submit a form. 我正在使用jquery ajax plugin提交表单。

$('#profile-form').ajaxForm({
            success:function(response, statusText, xhr, $form){
                console.log(statusText,response,xhr);
            },
            beforeSubmit : function(formData, jqForm, options){
                if ($('#permissions').data("permissionsModified") == true){
                    formData.push({name : 'selectedPermissions', value : JSON.stringify($('#permissions').data('selected'))});
                }
            }
        });

The server sends a redirect request back and the following is displayed on the firebug console : 服务器发送回重定向请求,并在firebug控制台上显示以下内容:

302 Moved Temporarily 302暂时移动

in front of the action url of the form. 在表单的操作网址之前。 Immediately after that, the redirect URL is shown and the 'request in progress' symbol in from of that keeps rotating . 之后,立即显示重定向URL ,从中“请求进行中”符号不断旋转 In the success callback of ajaxform, the statusText is "success" and the response text is the entire new redirect page. 在ajaxform的成功回调中, statusText为“成功”,响应文本为整个新的重定向页面。 How to check whether the server has redirected the requested (and then, how the display the redirected page on the browser) or there was a json reposnse from the server 如何检查服务器是否已重定向请求(然后,如何在浏览器上显示重定向的页面)或服务器是否有json回复

If I remember rightly, the browser should silently (transparently) follow any redirects issued over an AJAX request. 如果我没记错的话,浏览器应该静默地(透明地)遵循通过AJAX请求发出的任何重定向。

After a little digging, it appears I am correct, see point 2: http://www.w3.org/TR/XMLHttpRequest/#same-origin-request-event-rules 稍作挖掘后,看来我是正确的,请参见要点2: http : //www.w3.org/TR/XMLHttpRequest/#same-origin-request-event-rules

The only solution I can think of is a custom status code, but that's kind of stretching the paradigm a bit far. 我能想到的唯一解决方案是自定义状态代码,但这有点超出了范式。 Unfortunately not much else can be done. 不幸的是,别无他法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jquery文件上传插件如何获取从服务器发送的响应 - Jquery file upload plugin how to fetch Response sent from server 表单值不会发送回服务器 - Form values are not sent back to server 如何处理服务器对JQuery AJAX请求的两个单独响应? - How to handle two separate responses from the server to a JQuery AJAX request? 您如何在FireBug中知道Ajax请求后从服务器发回了什么JavaScript? - How can you tell in FireBug what JavaScript is being sent back from the server after an Ajax request? 如何处理从jQuery POST发送的C#服务器端的参数? - How to handle parameters on C# server side sent from jQuery POST? 如何处理来自快递服务器的Ajax发布响应? - How to handle ajax post response sent form express server? 如何正确处理javascript重定向? - how to handle javascript redirect correctly? 如何在使用jQuery post发送的post请求后获取表单参数 - how to get form parameters after post request sent with jQuery post 如何处理从 jquery ajax 发送的 arrays 与传统:false - How to handle arrays sent from jquery ajax with traditional : false 如何处理通过websocket在javascript服务器上通过javascript发送的blob? - how to handle blob sent via javascript through websocket back at the python server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM