var http_request; //is outside the declaration object, mainly in order to use //in Updatepage without refreshing the content function post (URL, Parameter) { if (http_request==null) { http_request = gethttprequest (); } if (!http_request) { alert ("xmlhttprequest initialization failed!"); } else { //adds a rnd random number at the end of the URL so that it does not occur to read IE cache if ( Url.indexof ("?")  > -1) { url = url + "&rnd=" + math.random (); } else { url = url + "? rnd=" + math.random (); } http_request.open ("POST", url, false); //Open Request //false Synchronous, true Async http_request.onreadystatechange = updatepage; / /Set callback method http_request.setrequestheader ("Content-length", Parameter.length); http_request.setrequestheader (' Content-Type ') , ' application/x-www-form-urlencoded '); http_request.send ( parameter); //Send Request }} //callback Method Function updatepage () { if (http_request.readystate == 4) { if (http_request.status == 200) { alert ("..."); / / } }}
The test found that, under Chrome 26, if a public variable was declared: Http_request
Then when the XMLHttpRequest is reused multiple times, if the parameter (content) is passed at post, the callback function is executed 2 times in a row: Updatepage ()
If the post has no arguments (content), only 1 callback functions will be executed: Updatepage ()
Tested under Firefox and IE, only 1 callback functions are performed: Updatepage ()
It's also easy to solve this problem with Chrome 26, which is re-initialized each time you use Http_request (XMLHttpRequest):
Http_request = Gethttprequest ();
There is a strange problem when you reuse XMLHttpRequest for post data under Chrome.