前言

=> 是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);
    }
})

相关文章:

  • 2021-10-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-24
  • 2022-12-23
猜你喜欢
  • 2021-12-05
  • 2022-12-23
  • 2021-09-14
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2021-08-03
相关资源
相似解决方案