Ajax 遵循HTTP协议

<script>
var xhr=new XMLHttpRequest();

xhr.open('POST','/add.http');//设置请求行

xhr.setRequestHeader('Foo','Bar');//设置请求头
//设置的请求体的格式内容(urlencoded),根据请求头 Content-Type 的变化而变化
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

xhr.send('key1=value1&key2=value2');//设置请求体
</script>

猜你喜欢

转载自www.cnblogs.com/lujieting/p/10291249.html