使用XMLHttpRequest发送post请求

var url = "https://www.douban.com/j/people/173453898/edit_signature";
var postStr = "ck=bJNY&signature=intro";
var ajax = null;
//IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
if(window.XMLHttpRequest) {
	ajax = new XMLHttpRequest();
}
//IE6, IE5 浏览器执行代码
else if (window.ActiveXObject) {
	ajax = new ActiveXObject("Microsoft.XMLHTTP");
}
else{
	return;
}

ajax.open("POST", url, true);
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajax.send(postStr);

ajax.onreadystatechange = function() {
	if (ajax.readyState == 4 && ajax.state == 200) {
		alert("Done!");
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_37537965/article/details/85217357