jQuery版AJAX简易封装代码
网络编程 2021-07-04 20:00www.168986.cn编程入门
这篇文章主要为大家详细介绍了jQuery版AJAX简易封装代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
开发过程中,AJAX的应用应该说非常频繁,,jQuery的AJAX函数已经非常好用,长沙网络推广还是稍微整理下,方便不同需求下,可以简化输入参数,狼蚁网站SEO优化是实例代码
$(function(){ / ajax封装 url 发送请求的地址 data 发送到服务器的数据,数组存储,如{"date": new Date().getTime(), "state": 1} async 默认值: true。默认设置下,所有请求均为异步请求。如果需要发送同步请求,请将此选项设置为 false。 注意,同步请求将锁住浏览器,用户其它操作必须等待请求完成才可以执行。 type 请求方式("POST" 或 "GET"), 默认为 "GET" dataType 预期服务器返回的数据类型,常用的如xml、html、json、text suessfn 成功回调函数 errorfn 失败回调函数 / jQuery.syncAjax=function(url, data, async, type, dataType, suessfn, errorfn) { async = (async==null || async=="" || typeof(async)=="undefined")? "true" : async; type = (type==null || type=="" || typeof(type)=="undefined")? "post" : type; dataType = (dataType==null || dataType=="" || typeof(dataType)=="undefined")? "json" : dataType; data = (data==null || data=="" || typeof(data)=="undefined")? {"date": new Date().getTime()} : data; $.ajax({ type: type, async: async, data: data, url: url, dataType: dataType, suess: function(d){ suessfn(d); }, error: function(e){ errorfn(e); } }); }; / ajax封装 url 发送请求的地址 data 发送到服务器的数据,数组存储,如{"date": new Date().getTime(), "state": 1} suessfn 成功回调函数 / jQuery.jsonAjax=function(url, data, suessfn) { data = (data==null || data=="" || typeof(data)=="undefined")? {"date": new Date().getTime()} : data; $.ajax({ type: "post", data: data, url: url, dataType: "json", suess: function(d){ suessfn(d); } }); }; / ajax封装 url 发送请求的地址 data 发送到服务器的数据,数组存储,如{"date": new Date().getTime(), "state": 1} dataType 预期服务器返回的数据类型,常用的如xml、html、json、text suessfn 成功回调函数 errorfn 失败回调函数 / jQuery.jsonAjax2=function(url, data, suessfn, errorfn) { data = (data==null || data=="" || typeof(data)=="undefined")? {"date": new Date().getTime()} : data; $.ajax({ type: "post", data: data, url: url, dataType: "json", suess: function(d){ suessfn(d); }, error: function(e){ errorfn(e); } }); }; });
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。
上一篇:js实现文字截断功能
下一篇:原生JS实现首页进度加载动画
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指