[英]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.