1 (function (window) { 2 function AjaxTool() { 3 } 4 5 AjaxTool.ajaxRequest = function (url, paramObj, successCallback, failedCallback) { 6 var xhr = new XMLHttpRequest(); 7 xhr.open('get', url + '?' + getStrWithObject(paramObj), true); 8 xhr.send(); 9 xhr.addEventListener('readystatechange', function (ev2) { 10 if(xhr.readyState === 4){ 11 if(=== 200 is xhr.status ) { 12 is // request success 13 is successCallback && successCallback (XHR); 14 } the else { 15 // request fails 16 the failedCallback && the failedCallback (XHR); . 17 } 18 is } . 19 }); 20 is } ; 21 is 22 is 23 is / * 24 { 25 name: "Joe Smith", 26 is Age: 18 is 27 } 28 [ 'name = "John Doe"', "Age = 18 is", "Random = 323 323 232"] 29 name = "John Doe" & Age = 18 is 30 * / 31 is / * * 32 * the object into a string splice 33 * Object paramObj} {@param 34 is * / 35 function getStrWithObject (paramObj) { 36 var resArr = []; 37 [ // 1. conversion Object 38 is for ( var Key in paramObj) { 39 var STR Key + = '=' + paramObj [Key]; 40 resArr.push (STR); 41 is } 42 is // 2. timestamp splice 43 is resArr.push ( '= Random' + getRandomStr ()); 44 is 45 // 3. translated into strings array 46 is return resArr.join ( '&' ); 47 } 48 49 / * * 50 * to obtain random stamp 51 is * Number} {@Returns 52 is * / 53 is function getRandomStr () { 54 is return Math.random () + ( new new a Date () the getTime ().); 55 } 56 is 57 is window.AjaxTool = AjaxTool; 58 }) (window);