/** * Cross-browser HTTP GET request * @param {string} url The url of HTTP GET request * @param {function} callback The callback function if HTTP GET succeeds * @param {function} failCallback The callback function if HTTP GET fails */HTTPGET=function(url,callback,failCallback){varxmlhttp;if(window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safarixmlhttp=newXMLHttpRequest();}else{// code for IE6, IE5xmlhttp=newActiveXObject("Microsoft.XMLHTTP");}xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){if(xmlhttp.status==200)callback(xmlhttp.responseText,url);elsefailCallback(url);}};xmlhttp.open("GET",url,true);xmlhttp.send();};
varurl='/demo/path?a=1&b=2';varcallback=function(responseText,url){// write your own handler for success of HTTP GETalert('responseText from url '+url+':\n'+responseText);};varfailCallback=function(url){// write your own handler for failure of HTTP GETalert('fail to get '+url);};HTTPGET(url,callback,failCallback);
Note that you can only make requests in the same domain. To make cross-domain
requests, please see reference [1] for more detail. To make cross-browser HTTP
POST request, please see reference [2]. To make HTTP POST requests to GAE
Python server, see reference [3].