Forum Moderators: open
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
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.