1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
function ajax(method, url, callback, data, flag) { var xml = null; if(window.XMLHttpRequest) { xml = new XMLHttpRequest(); }else { xml = new ActiveXObject('Microsoft.XMLHttp'); } method = method.toUpperCase(); if(method == 'GET') { var date = new Date(); var timer = date.getTime(); xml.open(method, url +'?'+data + '&timer='+timer, flag); xml.send(); }else if(method == 'POST') { xml.open(method, url, flag); xml.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xml.send(data); } xml.onreadystatechange = function () { if(xml.readyState == 4) { if(xml.status == 200) { callback(xml.responseText); } } } }
|