ajax 接收json 格式

来源:互联网 发布:阿里云幕布 收费 编辑:程序博客网 时间:2024/04/29 22:26
var xhr = new XMLHttpRequest();function t1(){xhr.open('post','a3.php');xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');  //post 必写xhr.onreadystatechange = function (){if(xhr.readyState == 4){var obj = eval('(' + xhr.responseText + ')')  //把字符串转成了JS对象~~alert(obj.username)   //直接读取对象属性~}}xhr.send(null);  //有没有数据都要send()}</script></head><body> <input type="button" value="接收json格式" onclick="t1();" />

原创粉丝点击