前言
=> 是ES6中的arrow function
x=>x+6
就相当于
function(x){ ???return x+6;}
正文
XMLHttpRequest
a=new XMLHttpRequest();a.open("POST",url,true);a.send("username=aaa");a.onreadystatechange=function(){ ???if(a.readystate==4&&a.status==200){ ???????alert(a.responseText); ???}}
fetch
fetch(url,{ ???method:"POST", ???headers:{"Content-Type:application/x-www-form-urlencoded"}, ???body:"username=aaa"}).then(function(res){ ???return res.text();}).then(function(data){ ???alert(data);}) ???
或
fetch(url,{ ???method:"POST", ???headers:{"Content-Type:application/x-www-form-urlencoded"}, ???body:"username=aaa"}).then(res=>res.text()).then(data=>alert(data))
上面两种是相同的
jQuery
$.post(url,{"username":"aaa"},function(text){ ???alert(text);})
$.ajax({ ???type:"POST", ???url:url, ???data:"username=aaa", ???success:function(text){ ???????alert(text); ???}})
提起Ajax请求的方式(POST)
原文地址:https://www.cnblogs.com/hf99/p/9807013.html