Hi I'm not sure exactly how to describe this problem, so I'm hoping the code will explain my problem. The php script ( phppage.php ) called by the ajax function does nothing more than echo hello world.
When the alert('a') line is left in the recall function withing the ajax function, then the code works as expected, and the final line pops up the message "hello world". However then the alert('a') line is commented out, then the final line does not give "hello world", but the value 13, as is set in the constructor function.
I'm trying this on firefox 3.6.18
Any help would be gratefully appreciated.
function A() {
this.b = 13;
function finish(context,response) {
context.b = response;
}
ajax(finish,this);
}
A.prototype = {
constructor: A
}
function ajax(callback,context) {
var http = new XMLHttpRequest();
var url = "phppage.php";
http.open("GET", url, true);
http.onreadystatechange = recall;
function recall() {
alert('a');
if(http.readyState == 4 && http.status == 200) {
callback(context,http.responseText);
}
}
http.send(null);
}
var d = new A();
alert(d.b);