Ajax與Axios

ajax是對原生xhr封裝,除此之外還增添了對於JSONP支持
例;

$.ajax({
type:"post",
url:url路徑
data:data
dataType:dataType;
success:function(data){
 console.log(data)
 }
 error:function(){}
 });

原生xhr請求

var xhr=new XMLHTTPRequest()
xhr.open('GET',url);
xhr.reponseType="json";
xhr.οnlοad=function(){
console.log(xhr.response);
};
xhr.send();

ajax針對MVC,不符合MVVM
JQuery整個項目太大。單線使用ajax卻要引入整個Jquery不合理

axios 對原生xhr封裝從Promise實現版本,符合最新es規範
優點,1,體積小,2提供了併發的封裝

axios({
method:"post",//求get
url:'/user/li'
data:{
fistname:'fird'
lastname:'abs'
}
}).then(function(response{
console.log(response);
}).cath(function(error){
console.log(err)
});
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章