//下面是原生的js實(shí)現(xiàn)的ajax
function myajax(){
var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var result = JSON.parse(xmlhttp.responseText);
console.log(result);
}
}
xmlhttp.open("POST", "/--------", true);//如果不跨域的話填個(gè)相對(duì)路徑的接口地址就好蟆淀,省略了域名
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send();//send()里面可以加ajax提交的數(shù)據(jù)
}