您的位置:首页 > 理论基础 > 计算机网络

XMLHttpRequest对象使用“POST”方法,需要设置“setRequestHeader”

2017-06-17 00:00 696 查看
var getjson = function(){
var xhr = new XMLHttpRequest();
xhr.open("POST","ajax.php",true);
//post方法需要设置header头"setRequestHeader"
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xhr.send("id=2046");
xhr.onreadystatechange = function(){
if(xhr.readyState==4&&xhr.status==200){
var obj = JSON.parse(xhr.responseText);
document.querySelector("main").innerHTML = obj.classify;
};
};
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  javascript ajax
相关文章推荐