gpt4 book ai didi

javascript - jquery ajax 表单 - 如何获取重定向 url?

转载 作者:搜寻专家 更新时间:2023-11-01 04:34:23 25 4
gpt4 key购买 nike

我正在使用 ajax 表单 jquery 插件通过 ajax 提交表单(在对话框中)。

这工作正常,然后我从服务器返回 html 响应。响应来 self 无法修改的标准发布后重定向 php 页面。

有没有办法使用 jquery(在 ajax 回调中)获取此重定向的 url(最终 GET 位置)?

  $j('span.sfAutocomplete a').click(function(e){
var url = this.href;
var $dialog = $j('<div id="ajaxDialog"></div>').appendTo('body')
.load(
url,
'sfAutocomplete=true',
function (responseText, textStatus, XMLHttpRequest) {
$dialog.dialog({ autoOpen: true });
//
// Ajax submit
//
$j('#ajaxDialog form').submit(function() {
function showResponse(responseText, statusText) {

// how to get the redirect url ?

}
$j(this).ajaxSubmit({
success: showResponse
});
return false;
});
}
);
return false;
});

最佳答案

我没用过你用的插件,但是如果你用jQuery Ajax command ,您收到 XMLHttpRequest 对象作为 complete 事件的参数。然后,您可以从返回的 HTTP header 中获取发布 URL。请尝试以下操作:

$.ajax({
url:'your.url',
data:'your data',
complete: function(xhr,textstatus) {
// xhr.responseText contains the response from the server
var allheaders = xhr.getAllResponseHeaders();
// this will get all headers as a string - if you want them as an object...
var eachheader = allheaders.split('\n');
var headers = {};
for(i = 0; i < eachheader.length; i++) {
if ($.trim(eachheader[i]) !== '') {
headersplit = eachheader[i].split(':');
headers[headersplit[0]]=$.trim(headersplit[1]);
}
}
}
});

此代码复制自 this thread .

关于javascript - jquery ajax 表单 - 如何获取重定向 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1666205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com