function getdata(url,callback) { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { var result = xmlhttp.responseText; callback(result) } } xmlhttp.open("POST",url,true); xmlhttp.send(); }
send the name of the callback function as the second argument to this function. You can get the response text for this function. just. But you cannot directly return anything from an asynchronous call.
Vignesh
source share