Resolves a JSON object to a string and replaces the corresponding symbol function jsonstringify (obj) {return json.stringify (obj). Replace (/"|{|}
/g, ""). Replace (/:/g, "="). Replace (/,/g, "&");
function Getserverdatauseajax (method, URL, params) {//Start initializing XMLHttpRequest object var http_request = false; if (window.
XMLHttpRequest) {//mozilla browser http_request = new XMLHttpRequest ();
if (http_request.overridemimetype) {//Set MIME category Http_request.overridemimetype (' Text/xml '); ' Else if ' window.
ActiveXObject) {//IE browser try {http_request = new ActiveXObject ("Msxml2.xmlhttp");
catch (e) {try {http_request = new ActiveXObject ("Microsoft.XMLHTTP");
catch (e) {}} if (!http_request) {//exception, create object instance failed Window.alert ("Cannot create XMLHttpRequest object instance.");
return false;
///Different request method request process different//development process 80% development Use GET method request if (method.tolowercase () = = "Get") {//here plus timestamp is to solve the problem of low version IE browser cache
Another: Here is an extra method for parsing the incoming JSON object and string recombination URL = "?" + jsonstringify (params) + "Xtamp" + New Date (). GetTime (); If not IE browser execute//if (Navigator.userAgent.indexOf ("MSIE") <=0) {//Netscape.security.Privilege
Manager.enableprivilege ("Universalbrowserread");
//Note This is two times encodeURI () Http_request.open (method, encodeURI (encodeURI (URL)), true); Functions that process return information Http_request.onreadystatechange = function () {if (http_request.readystate!= 4) {//Judge object state//i
D loading_inserhtml//document.getElementById (' Merchname '). innerhtml= "Loading data ...";
Alert (4); else {if (Http_request.status = | | http_request.status = 0) {//information has been successfully returned, start processing information var strhtml = Http_re
Quest.responsetext;
ok_innerhtml//document.getelementbyid (' Merchname '). innerhtml=strhtml;
alert (strhtml); else {//page is not normal alert ("the page you are requesting has an exception.)
");
}
}
};
Start sending request http_request.send (NULL); else {if (method.tolowercase () = "POST") {if (method.tolowercase () = "post") {HTTP_request.open (method, URL, true);
Http_request.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Functions to process return information Http_request.onreadystatechange = function () {if (http_request.readystate!= 4) {//Judge object state
document.getElementById (' Merchname '). innerhtml= "Loading data ...";
Alert (4); else {if (Http_request.status = | | http_request.status = 0) {//information has been successfully returned, start processing information var strhtml = htt
P_request.responsetext;
document.getElementById (' Merchname '). innerhtml=strhtml;
alert (strhtml); else {//page is not normal alert ("the page you are requesting has an exception.)
");
}
}
};
Start sending Request Http_request.send (Jsonstringify (params));
else {//http Request category parameter Error Window.alert ("HTTP request class parameter error ...");
return false;
function test () {//{name: ' Jack ', age:88}/Note The parameter object given here is the JSON Object format getserverdatauseajax ("Get", "test", {
Name: "Heaven and Earth", age:88}); }
server-side decoding Urldecoder.decode (Request.getparameter ("name"), "UTF-8") is required for use