1, Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
This setting is only used by the Post method
2, X-requested-with XMLHttpRequest is the Ajax asynchronous request way
Use
Request.getheader ("X-requested-with");
Is null, the traditional synchronization request;
For XMLHttpRequest, then an Ajax asynchronous request.
function ajax (URL, parms) {parms = Parms | | {};var req = new XMLHttpRequest (), post = Parms.post | | Null,callback = Parms.callback | | Null,timeout = Parms.timeout | | Null;req.onreadystatechange = function () {if (req.readystate! = 4) return;//Errorif (req.status! = && Req . Status = 304) {if (callback) callback (false); return;} if (callback) callback (Req.responsetext);}; if (POST) {Req.open (' post ', url, true); Req.setrequestheader (' Content-type ', ' application/x-www-form-urlencoded ');} else {req.open (' GET ', url, true);} Req.setrequestheader (' X-requested-with ', ' XMLHttpRequest '); Req.send (post); if (timeout) {setTimeout (function () { Req.onreadystatechange = function () {};req.abort (); if (callback) callback (false);}, timeout);}}
Call Mode:
Ajax (' dataset.php?start= ' + +start + ' &count= ' + +count, {callback:function (data) {data = Json.parse (data); Myscroll. Updatecache (start, data);});
JavaScript Advanced Programming: A plug-in for Ajax