当前位置: 移动技术网 > IT编程>开发语言>JavaScript > js中的AJAX

js中的AJAX

2019年11月12日  | 移动技术网IT编程  | 我要评论
js中ajax get请求的写法 var xhr=new XMLHttpRequest(); xhr.open('get','http://rap2api.taobao.org/app/mock/229494/news?content='+ inp.value) xhr.send(); xhr.on ...
js中ajax get请求的写法 
var xhr=new xmlhttprequest(); xhr.open('get','http://rap2api.taobao.org/app/mock/229494/news?content='+ inp.value) xhr.send(); xhr.onreadystatechange=function () { if (xhr.readystate==4) { // console.log(xhr.responetext } }
js中post请求的写法
var xhr = new xmlhttprequest(); xhr.open('post',"http://192.168.1.5/archives/register.php",true); // 如果是post请求 必须加上请求头 xhr.setrequestheader("content-type","application/x-www-form-urlencoded"); xhr.send("username="+user.value+'&password='+pass.value); xhr.onreadystatechange =function(){ if (xhr.readystate==4) { var obj = json.parse(xhr.responsetext); console.log(obj.responsecode); if (obj.responsecode=="0") { window.location.href = "denglu.html" } } }

 

 

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网