JavaScript Ajax Get Commit data

Source: Internet
Author: User

Tags: submit    amp   response   body   test    encodeuri   status   eof   ess   

<! DOCTYPE html><html><head> <title> Package ajax</title></head><body><!--05:59 Ajax under--><script type= "Text/javascript" > Function createxhr () {if (typeof XMLHttpRequest! = "undefined") {retur N new XMLHttpRequest (); } else if (typeof activexobject! = "undefined") {var versions = ["msxml.2.xmlhttp.6.0", "msxml.2.xmlhttp.3.0", "msxml.2.x Mlhttp "]; for (var i = 0; i<versions.length;i++) {try{return new ActiveXObject (Version[i]);} catch (E) {//Because the class loop will report a mistake, skip some errors}}} else {throw new Error ("Your system or browser does not support XHR objects! "); } } The name value pair converts the string function params (data) {var arr = []; for (var i in data) {Arr.push (encodeURIComponent (i) + "=" +encodeuricompone NT (Data[i])); } return Arr.join ("&"); }//Ajax function Ajax (obj) {var xhr=createxhr (); obj.url=obj.url+ "? rand=" +math.random () + "&" +params (; = params (; if (Obj.method = = = "GET") {obj.url=obj.url+ "&";} xhr.onreadystatechange = function () {if (xhr.readystate = = 4) {if (Xhr.status = =) {obj.success (Xhr.responsetext)} else {Console.log ("Error code:" +xhr.status+ "-Error message" +xhr.statustext "); }}} (Obj.method,obj.url,obj.async); Xhr.send (NULL); }//Use Ajax AddEventListener ("click", Function () {Ajax ({method: "GET", url: "test.php", data:{"Na&me": "Ping", "age" : 18},//Upload object to text, then object callback Success:function (text) {Console.log ("Receive success data:" +text);}, async:true}); },false);</script></body></html>

JavaScript Ajax get submit data

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: