Hi:
I am facing a problem in ajax.
My code functionality is retrieving data from database. For it i am using ajax.
i am including the code below which contains ajax function:
<script>
var req;
var which;
function fetchCorpClassTaxonomy(url) {
alert("entered into Ajax function");
if (window.XMLHttpRequest) { // Non-IE browsers
alert("NON IE Block is Invoked");
req = new XMLHttpRequest();
req.onreadystatechange = processStateChange;
try {
req.open("GET", url, true);
} catch (e) {
alert(e);
}
req.send(null);
} else if (window.ActiveXObject) { // IE
alert("entered into IE block");
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
alert("entered into if(req)");
req.onreadystatechange = processStateChange;
req.open("GET", url, true);
alert("readystate: "+ req.readyState);
req.send();
}
}
}
function processStateChange() {
alert("entered into processStateChange()");
if (req.readyState == 4) { // Complete
if (req.status == 200) { // OK response
... STUFF REMOVED ...;
}
} else {
alert("Problem: " + req.statusText);
}
}
}
</script>
I am getting response from action class so there is no problem in my other code.
when fetchCorpClassTaxonomy(url) function is called it is going to IE block since i am using IE 7.0
After that
alert("readystate: "+ req.readyState);
is also coming.
but the function processStateChange() is not called.
The alert just inside the function :
alert("entered into processStateChange()"); is also not executing.
The problem is function processStateChange() is not called.
Please give me your valuable suggestions As Soon As Possible for solving the problem. Since i am new to Ajax I am not able to find the solution.
Thanks.....
[[jsudds.MSFT]] On IE, XMLHttpRequest object properties are reset when you call the open method. The onreadystatechange handler you just set on the line above is thrown away. Just switch the order of those two lines.
TO RECAP: Calling the open method initializes the request object. If you have set properties (such as onreadystatechange) it is reset to initial default values (NULL). So, do all your initialization between OPEN and the final call to SEND.