$function(){
$.ajaxSetup({
cache:false //清除缓存
});
}
//ajax的get方法
function getAjax(get_url){
var result = "";
$.ajax({
type:'get',
dataType:'json',
contentType:'application/json;charset=utf-8',
url:get_url,
success:function(result1){
result = result1;
},
error:function(XMLHttpRequest,textStatus,errorThrown){
alert(errorThrown);
},
async:false
});
return false;
}
//ajax的post方法,参数为url,data
function postAjax(url_post,data){
var result= "";
$.ajax({
type:'post',
contentType:'application/json;charset=utf-8',
url:url_post,
data:JSON.stringify(data),
success:function(result1){
result = result1;
},
error:function(XMLHttpRequest,textStatus,errorThrown){
alert(errorThrown);
},
dataType:'json',
async:false
});
return result;
}
//ajax的post方法 参数为url
function postAjaxNoData(url_post){
var result = "";
$.ajax({
type:'post',
dataType:'json',
contentType:'application/json;charset=utf-8',
url:url_post;
success:function(result1){
result = result1;
},
error:function(XMLHttpRequest,textStatus,errorThrown){
alert(errorThrown);
},
async:false
});
return result;
}
//ajax的put方法 参数为url data
function putAjax(url_put,data){
var result = "";
$.ajax({
type:'put',
dataType:'json',
url:url_put,
contentType:'application/json;charset=utf-8',
data:JSONstringify(data),
success:function(result1){
result = result1;
},
error:function(XMLHttpRequest,textStatus,errorThrown){
alert(errorThrown);
},
async:false
});
return result;
}
//ajax的put方法 参数为url
function putAjaxNoData(url_put){
$.ajax({
type:'put',
contetnType:'application/json;charset=utf-8',
url:url_put,
dataType:'json',
success:function(result1){
result = result1;
},
error:function(XMLHttpRequest,textStatus,errorThrown){
alert(errorThrown);
},
async:false
});
return result;
}
//ajax的delete方法 参数为url
function deleteAjax(url_delete){
$.ajax({
type:'delete',
dataType:'json',
url:url_delete,
contentType:'application/json;charset=utf-8',
success:function(result1){
result = result1;
},
error:function(XMLHttpRequest,textStatus,errorThrown){
alert(errorThrown);
},
async:false
});
return result;
}
常用ajax封装的方法
最新推荐文章于 2021-08-05 15:11:01 发布