My Javascript function request to a aspx page. İts Code:
var xhr = ("XMLHttpRequest" in window) ? new XMLHttpRequest() : new ActiveXObject("Msxml3.XMLHTTP");
xhr.open("GET", = 'http://www.example.net/abc.aspx', true);
xhr.send("");
After this request I want to send a response back from this page and catch it on the client side. How do I do that?
You have to do a little more to get it work cross-browser, but once it's done you've got a reusable function, without any library.
To get the response, add a
readystatechange
event handler function. This will get called back when the response is ready to read:Incidentally:
Whilst
in
is in general a good way to test whether a property exists, this is one of the very few places where it's not ideal.The problem is that in IE7+, when the ‘native XMLHttpRequest’ option is turned off,
XMLHttpRequest
still exists as a property inwindow
, but with the unusable valuenull
. So it's better in this specific case to use a simple truth test, which will allow fallback to ActiveX in the (unlikely) event that this option is disabled:To get the response from
XMLHttpRequest
in asynchronous mode (third parameter istrue
for theopen()
method) you have to set theonreadystatechange
property to a callback function. This function will be called back when the response is ready at the browser:You may want to check out the following article for further reading on the topic: