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; }; }; };
相关文章推荐
- jQuery的ajax()检验用户名;通过jQuery的load()/get()/post()方法实现;使用XMLHTTPRequest对象来进行AJAX的异步数据交互
- 原始ajax通过xmlHttpRequest对象的send()方法提交数据--Get方式和Post方式
- javascript获取xml对象的方法(使用XMLHttpRequest)
- Ajax学习(三)——XMLHttpRequest对象的五步使使用方法
- AJAX 简介 及 XMLHttpRequest对象的使用方法
- 在今天的测试过程中,我刚开始使用get方法传递参数,出现乱码,但是使用post传参数好着的,需要在tomcat的server.xml里面进行设置URIEncoding="UTF-8"即可
- 黑马程序员---XMLHttpRequest 对象open参数中使用post与get区别
- ajax 快速入门,ajax底层使用的五个步骤;XMLHttpRequest对象详解;XMLHttpRequest常用属性;XMLHttpRequest常用方法
- ajax中XMLHttpRequest对象的open()方法GET和POST方式区别
- dotnet 使用HttpWebRequest向Https Post数据时,需要证书确认的解决方法
- XMLHttpRequest 对象的方法及属性
- AJAX中同时发送多个请求XMLHttpRequest对象处理方法
- AJAX核心对象-- XMLHttpRequest 对象使用详解 (二)
- Ajax-核心对象--XMLHttpRequest 对象使用详解
- AJAX中同时发送多个请求XMLHttpRequest对象处理方法
- 使用XMLHttpRequest对象向服务器发送简单的请求
- 使用 XMLHttpRequest 创建方法的优缺点
- XMLHttpRequest 对象的方法与属性
- Ajax无刷新方法纵览(1)—XMLHttpRequest对象
- XMLHttpRequest对象的属性和方法