1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
function post(url, param, callback) { var xmlhttp = new XMLHttpRequest(); var paraStr = ''; xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { callback(JSON.parse(xmlhttp.responseText)); } }; xmlhttp.open('post', url, true); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.setRequestHeader("If-Modified-Since", "0"); //下面这行 请求为ajax xmlhttp.setRequestHeader("X-Requested-With","XMLHttpRequest"); for (key in param) { paraStr += key + "=" + encodeURIComponent(param[key]) + "&" } paraStr = paraStr.substr(0, paraStr.length - 1); xmlhttp.send(paraStr);
}
|
近期评论