jQuery.ajax对应的post/get/delete/put请求方法封装
发表于:2021-12-08 15:02:57浏览:2414次
jQuery ajax中的post/get/delete/put请求方法的写法过于繁琐,所以现在封装成如下简便的形式:
1、获取数据ajax-get请求
/**
* 获取数据ajax-get请求
*/
$.getJSON = function (url,data,callback){
$.ajax({
url:url,
type:"get",
contentType:"application/json",
dataType:"json",
timeout:10000,
data:data,
success:function(data){
callback(data);
}
});
};2、提交json数据的post请求
/**
* 提交json数据的post请求
*/
$.postJSON = function(url,data,callback){
$.ajax({
url:url,
type:"post",
contentType:"application/json",
dataType:"json",
data:data,
timeout:60000,
success:function(msg){
callback(msg);
},
error:function(xhr,textstatus,thrown){
}
});
};3、修改数据的ajax-put请求
/**
* 修改数据的ajax-put请求
*/
$.putJSON = function(url,data,callback){
$.ajax({
url:url,
type:"put",
contentType:"application/json",
dataType:"json",
data:data,
timeout:20000,
success:function(msg){
callback(msg);
},
error:function(xhr,textstatus,thrown){
}
});
};4、删除数据的ajax-delete请求
/**
* 删除数据的ajax-delete请求
*/
$.deleteJSON = function(url,data,callback){
$.ajax({
url:url,
type:"delete",
contentType:"application/json",
dataType:"json",
data:data,
success:function(msg){
callback(msg);
},
error:function(xhr,textstatus,thrown){
}
});
}; 推荐文章
- PHP中的public,static,private,protected,final,const,abstract解析与区别
- jQuery.ajax对应的post/get/delete/put请求方法封装
- 微信H5版使用php Ffmpeg将微信录音amr转mp3
- PHP实现隐藏部分手机号码,身份证号码
- ERP、进销存、仓储管理系统到底有什么不同?
- ThinkPHP6接入阿里云短信实战:阿里云短信验证码登录
- Thinkphp6使用mPdf实现生成pdf文件
- 开源OA办公系统 — 勾股OA 5.6.8 新春版发布,企业办公的卓越选择
- Layui的table模块导出所有数据,无需修改代码,完美解决方案
- 不知道是什么时候起,直播行业也开始内卷了

