Forum Moderators: open

Message Too Old, No Replies

Never reach ready state 4

         

supermanjace

7:02 am on Oct 9, 2008 (gmt 0)

10+ Year Member



Can any body figure why I never reach ready state 4 with the below ajax?

function createRequestObject() {
var ro
var browser = navigator.appName
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP")
}else{
ro = new XMLHttpRequest()
}
return ro
}

var http = createRequestObject()

function sndReq(obj) {
var test = obj.innerHTML

http.open('get', 'bluepalmstest.xml', true)
http.onreadystatechange = handleResponse(test);
http.send(null)
}

function handleResponse(test) {
alert(test)
alert("test")

if(http.readyState == 4){
alert("test")


}

}

I am calling the above with a simple anchor onClick
<a href="#" id="here" onClick="sndReq(this);"><span class="brand">testing</span></a>

THE XML file is correctly referenced. That's not the issue. I am stumped...

Thanks all

Little_G

11:30 am on Oct 9, 2008 (gmt 0)

10+ Year Member



Hi,

You are assigning the handler incorrectly, try:

http.onreadystatechange = function(){handleResponse(test);};

Andrew

Fotiman

3:23 pm on Oct 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




http.onreadystatechange = handleResponse(test);

The reason that doesn't work is because you are executing handleResponse right here (the parenthesis tell the function to execute), and assigning the return value to http.onreadystatechange. As Little_G pointed out, you can wrap that in an anonymous function so that it won't execute.