1var ajax = function(options) { 2 /** 3 * ä¼ å ¥æ¹å¼é»è®¤ä¸ºå¯¹è±¡ 4 * */ 5 options = options || {}; 6 /** 7 * é»è®¤ä¸ºGETè¯·æ± 8 * */ 9 options.type = (options.type || "GET").toUpperCase(); 10 /** 11 * è¿åå¼ç±»åé»è®¤ä¸ºjson 12 * */ 13 options.dataType = options.dataType || 'json'; 14 /** 15 * é»è®¤ä¸ºå¼æ¥è¯·æ± 16 * */ 17 options.async = options.async || true; 18 /** 19 * 对éè¦ä¼ å ¥çåæ°çå¤ç 20 * */ 21 var params = getParams(options.data); 22 var xhr; 23 /** 24 * å建ä¸ä¸ª ajaxè¯·æ± 25 * W3Cæ ååIEæ å 26 */ 27 if (window.XMLHttpRequest) { 28 /** 29 * W3Cæ å 30 * */ 31 xhr = new XMLHttpRequest(); 32 } else { 33 /** 34 * IEæ å 35 * @type {ActiveXObject} 36 */ 37 xhr = new ActiveXObject('Microsoft.XMLHTTP') 38 } 39 xhr.onreadystatechange = function() { 40 if (xhr.readyState == 4) { 41 var status = xhr.status; 42 if (status >= 200 && status < 300) { 43 options.success && options.success(xhr.responseText, xhr.responseXML); 44 } else { 45 options.fail && options.fail(status); 46 } 47 } 48 }; 49 if (options.type == 'GET') { 50 xhr.open("GET", options.url + '?' + params, options.async); 51 52 xhr.send(null) 53 54 console.log('请æ±å¤±è´¥') 55 56 } else if (options.type == 'POST') { 57 /** 58 *æå¼è¯·æ± 59 * */ 60 xhr.open('POST', options.url, options.async); 61 /** 62 * POST请æ±è®¾ç½®è¯·æ±å¤´ 63 * */ 64 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 65 /** 66 * åé请æ±åæ° 67 */ 68 xhr.send(params); 69 } 70} 71/** 72 * å¯¹è±¡åæ°çå¤ç 73 * @param data 74 * @returns {string} 75 */ 76var getParams =function(data) { 77 var arr = []; 78 for (var param in data) { 79 arr.push(encodeURIComponent(param) + '=' + encodeURIComponent(data[param])); 80 } 81 // arr.push(('randomNumber=' + Math.random()).replace('.')); 82 return arr.join('&'); 83}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.