Question:
I need some help with ajax?
Manish
2006-08-21 06:01:43 UTC
As you know that ajax is asynchronous (happening at different times), that means say if i have two functions called in a sequence, one is for the ajax - goes to the server and fetches the data, and second one is to refresh the targetDiv to display the result, but the problem is that, if the internet is slow, the first one waits for the reponse from the server while the otherone refreshes the page even though the response is not received. and when the response is received, the targetDiv is not refreshed.

How can i call functions in sequence, say call a function or functions after the response is received.
Three answers:
Drew
2006-08-21 06:17:04 UTC
Are you using the XMLHttpRequest object? It provides functionality that does just what you want. You should be using an onreadystatechange event to trigger the function that fills the target div, not just calling them directly in sequence.
?
2016-11-27 02:12:28 UTC
relies upon on the context. Ajax in Greek delusion replace into between the major severe warriors on the Greek section interior the Trojan conflict. Ajax in football is likely going one among the major typically used ecu communities, depending in Amsterdam, Netherlands. Ajax in software Programming stands for Asynchronous JavaScript and XML, a fashion for optimizing the way a cyber web website is rendered onto the browser. Ajax is likewise an commercial air purifier from Colgate-Palmolive.
2006-08-21 06:38:37 UTC
I agree with Drew,



(this is a pretty rough example but demonstrats the point)



function ajax(paramaters) {

// Mozilla version

if (window.XMLHttpRequest) {

xhr = new XMLHttpRequest();

}

// IE version

else if (window.ActiveXObject) {

xhr = new ActiveXObject("Microsoft.XMLHTTP");

}

xhr.open("POST","myPage.php");

xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');

xhr.send(paramaters);



// THE onreadystatechange FUNCTION



xhr.onreadystatechange= function() {

if (xhr.readyState==4) {

alert("I'm done loading");

document. getElementByID("Div") .innerHTML = xhr.responseText;

}

}





}


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...