开发者

How to get jQuery/AJAX final URL

开发者 https://www.devze.com 2023-01-04 03:31 出处:网络
When I run $.get or .load in jQuery, the request seems to follow 302 redirects perfectly fine and gives me ultimate开发者_StackOverflow response, which I can use in the callback for $.get or which plu

When I run $.get or .load in jQuery, the request seems to follow 302 redirects perfectly fine and gives me ultimate开发者_StackOverflow response, which I can use in the callback for $.get or which plugs into the this element for .load.

While I obviously have the original URL since I am in control of the string that's entered as the first argument in $.get or .load (it would also be helpful if I could get this directly in the callback to simplify things), how can access the final (after redirect) URL in the callback?

I suspect that it would be in the XMLHttpRequest object, for which I have found the specification.


I'm not sure (and Googling hasn't gotten me anywhere), but what about this unorthodox solution? var hiddenIframe = $('').attr({ style: 'display: none;' }).appendTo('body'); hiddenIframe.attr({ src: 'http://www.direct-me.com' }); hiddenIframe.load(function() { alert(hiddenIframe.attr('src')); }); Basically it just makes a hidden iframe, and then goes to your URL, and the callback for load *should* tell you the final URL.

It appears you cannot. You can get the original src, but then you cannot due to security issues.

0

精彩评论

暂无评论...
验证码 换一张
取 消