Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get response url in XMLHttpRequest?

There is a page (url), I request it by XMLHttpRequest, but I'm not getting response from requested url, It's directing request to another page,

requesting --- > page.php
getting reponse from > directedpage.php

and the question is how can I get response url? (directedpage.php in example)

like image 433
Okan Kocyigit Avatar asked Nov 08 '11 19:11

Okan Kocyigit


People also ask

How do I get the response from XMLHttpRequest?

It works by creating an XMLHttpRequest object and creating a listener for readystatechange events such that when readyState changes to DONE (4), the response is obtained and passed into the callback function provided to load() .

How do I find the URL of XMLHttpRequest?

The read-only XMLHttpRequest. responseURL property returns the serialized URL of the response or the empty string if the URL is null . If the URL is returned, any URL fragment present in the URL will be stripped away. The value of responseURL will be the final URL obtained after any redirects.

What is a response URL?

The Response/Receipt URL(s) are the Web addresses to which the payment gateway sends transaction responses and/or redirects customers to your website from the payment gateway hosted receipt page.

How do I get HTML from XMLHttpRequest?

Retrieving an HTML resource as a DOM using XMLHttpRequest works just like retrieving an XML resource as a DOM using XMLHttpRequest , except you can't use the synchronous mode and you have to explicitly request a document by assigning the string "document" to the responseType property of the XMLHttpRequest object after ...


1 Answers

The final URL (after following all redirects) is available in the responseURL attribute of a XMLHttpRequest instance. This feature is new and only supported in Firefox 32 stable in September 2014 [ref] and Chrome 37.0.2031.0 stable in August 2014 [ref] (and probably also Opera 24). responseURL is not (yet) supported in IE 11 or Safari 7 and older browsers. For these browsers, the previous answer is still true:

XMLHttpRequest automatically follows redirects, without saving the served URLs in a property. The Location header can neither be retrieved through the .getResponseHeader().

References:

  • https://groups.google.com/a/chromium.org/d/msg/blink-dev/AU6pAiYZ8J4/ec5jgoEDsF0J
  • https://bugzilla.mozilla.org/show_bug.cgi?id=998076
like image 82
Rob W Avatar answered Oct 17 '22 23:10

Rob W