// Use native js to encapsulate ajax // compatible with xhr object function createXHR () {if (typeof XMLHttpRequest! = "Undefined") {// non-IE6 browser return new XMLHttpRequest ();} else if (typeof ActiveXObject! = "Undefined") {// IE6 browser var version = ["MSXML2.XMLHttp. 6.0 "," MSXML2.XMLHttp. 3.0 "," MSXML2.XMLHttp ",]; for (var I = 0; I <version. length; I ++) {try {return new ActiveXObject (version [I]);} catch (e) {// skip} else {throw new Error ("your system or browser does not support XHR objects! ") ;}// Escape Character function params (data) {var arr = []; for (var I in data) {arr. push (encodeURIComponent (I) + "=" + encodeURIComponent (data [I]);} return arr. join ("&") ;}// encapsulate ajaxfunction ga_ajax (obj) {var xhr = createXHR (); obj. url = obj. url + "? Rand = "+ Math. random (); // clear the cached obj. data = params (obj. data); // escape string if (obj. method = "get") {// determines whether the get method is used to send obj. url + = obj. url. indexOf ("? ") ="-1 "? "? "+ Obj. data: "&" + obj. data;} // asynchronous if (obj. async = true) {// The onreadystatechange event xhr must be triggered during asynchronous processing. onreadystatechange = function () {// execution completed if (xhr. readyState = 4) {callBack () ;}} xhr. open (obj. method, obj. url, obj. async); // false is synchronous; true is asynchronous // "demo. php? Rand = "+ Math. random () + "& name = ga & ga", if (obj. method = "post") {xhr. setRequestHeader ("Content-Type", "application/x-www-form-urlencoded"); xhr. send (obj. data);} else {xhr. send (null);} // xhr. abort (); // cancel asynchronous request // synchronize if (obj. async === false) {callBack () ;}// return data function callBack () {// determine whether to return correct if (xhr. status = 200) {obj. success (xhr. responseText);} else {obj. error ("failed to get data, Error code:" + xhr. status + "error message:" + xhr. statusText) ;}}var html = document. getElementsByTagName ("html") [0]; html. onclick = function () {ga_ajax ({"method": "post", "url": "dem0o. php "," data ": {" name ":" gaga "," age ": 10000000," num ":" 12346 & 598 "}," success ": function (data) {alert (data) ;}, "Error": function (text) {alert (text) ;}, "async": false });}