PDA

View Full Version : AJAX stops at onreadystatechange function



Palko17
12-10-2007, 11:25 PM
Okay so I have this ajax code below, and it doesn't work... It doesn't even get into the onreadystatechange function, can anyone tell me what i've done wrong. Thank-you so much I've been working on this for 2 days!



var response = false;

function AJAXGet (url, target) {

httpRequest = new XMLHttpRequest();

httpRequest.open ('GET', url, true);

httpRequest.onReadyStateChange = function () {

if (httpRequest.stateChange==4) {

if (httpRequest.status==200) {

if (target=='self') {

response = httpRequest.responseText;

}

}

}

};

return response;

httpRequest.send(null);

}

Master_script_maker
12-11-2007, 12:39 AM
try changing it to this:


var response = false;

function AJAXGet(url, target) {

httpRequest = new XMLHttpRequest();

httpRequest.open('GET', url, true);

httpRequest.onReadyStateChange = function () {

if (httpRequest.stateChange==4) {

if (httpRequest.status==200) {

if (target=='self') {

response = httpRequest.responseText;

}

}

}

}

return response;

httpRequest.send(null);

Strangeplant
12-12-2007, 05:52 PM
There have been no replies, so I don't know if it is solved. But if it is still a problem, it may be that your
httpRequest.onReadyStateChange = function ()should be
httpRequest.onreadystatechange = function ()and that it should appear after the open. See http://www.dynamicdrive.com/forums/showthread.php?t=27081 for a script that works - just tailor it a little to get back your response text.