前言
=> 是ES6中的arrow functionajax
x=>x+6
就至關於app
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); })
或post
fetch(url,{ method:"POST", headers:{"Content-Type:application/x-www-form-urlencoded"}, body:"username=aaa" }).then(res=>res.text()).then(data=>alert(data))
上面兩種是相同的fetch
jQuery
$.post(url,{"username":"aaa"},function(text){ alert(text); })
$.ajax({ type:"POST", url:url, data:"username=aaa", success:function(text){ alert(text); } })