且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Ajax重定向后获取最终的URL?

更新时间:2023-11-26 16:50:04

我回答了类似的问题问题在这里: https://***.com/a/48445360/1398908

As I answered a similar question here: https://***.com/a/48445360/1398908

更好的解决方案是使用这样的自定义xhr对象提供jQuery的ajax:

A better solution is to supply jQuery's ajax with a custom xhr object like this:

var xhr = new XMLHttpRequest();

$.ajax({
    url: '/url',
    type: 'post',
    data: '...',
    xhr: function() {
         return xhr;
    }
});

然后您可以在任何回调中访问当前网址

Then you can access the current URL in any callback

success: function () {
    console.log(xhr.responseURL);
}