最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jQuery版AJAX簡(jiǎn)易封裝代碼

 更新時(shí)間:2016年09月14日 14:01:35   作者:靚仔小伙計(jì)  
這篇文章主要為大家詳細(xì)介紹了jQuery版AJAX簡(jiǎn)易封裝代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

開發(fā)過程中,AJAX的應(yīng)用應(yīng)該說非常頻繁,當(dāng)然,jQuery的AJAX函數(shù)已經(jīng)非常好用,但是小編還是稍微整理下,方便不同需求下,可以簡(jiǎn)化輸入?yún)?shù),下面是實(shí)例代碼:

$(function(){
  /**
   * ajax封裝
   * url 發(fā)送請(qǐng)求的地址
   * data 發(fā)送到服務(wù)器的數(shù)據(jù),數(shù)組存儲(chǔ),如:{"date": new Date().getTime(), "state": 1}
   * async 默認(rèn)值: true。默認(rèn)設(shè)置下,所有請(qǐng)求均為異步請(qǐng)求。如果需要發(fā)送同步請(qǐng)求,請(qǐng)將此選項(xiàng)設(shè)置為 false。
   *    注意,同步請(qǐng)求將鎖住瀏覽器,用戶其它操作必須等待請(qǐng)求完成才可以執(zhí)行。
   * type 請(qǐng)求方式("POST" 或 "GET"), 默認(rèn)為 "GET"
   * dataType 預(yù)期服務(wù)器返回的數(shù)據(jù)類型,常用的如:xml、html、json、text
   * successfn 成功回調(diào)函數(shù)
   * errorfn 失敗回調(diào)函數(shù)
   */
  jQuery.syncAjax=function(url, data, async, type, dataType, successfn, 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,
      success: function(d){
        successfn(d);
      },
      error: function(e){
        errorfn(e);
      }
    });
  };
  
  /**
   * ajax封裝
   * url 發(fā)送請(qǐng)求的地址
   * data 發(fā)送到服務(wù)器的數(shù)據(jù),數(shù)組存儲(chǔ),如:{"date": new Date().getTime(), "state": 1}
   * successfn 成功回調(diào)函數(shù)
   */
  jQuery.jsonAjax=function(url, data, successfn) {
    data = (data==null || data=="" || typeof(data)=="undefined")? {"date": new Date().getTime()} : data;
    $.ajax({
      type: "post",
      data: data,
      url: url,
      dataType: "json",
      success: function(d){
        successfn(d);
      }
    });
  };
  
  /**
   * ajax封裝
   * url 發(fā)送請(qǐng)求的地址
   * data 發(fā)送到服務(wù)器的數(shù)據(jù),數(shù)組存儲(chǔ),如:{"date": new Date().getTime(), "state": 1}
   * dataType 預(yù)期服務(wù)器返回的數(shù)據(jù)類型,常用的如:xml、html、json、text
   * successfn 成功回調(diào)函數(shù)
   * errorfn 失敗回調(diào)函數(shù)
   */
  jQuery.jsonAjax2=function(url, data, successfn, errorfn) {
    data = (data==null || data=="" || typeof(data)=="undefined")? {"date": new Date().getTime()} : data;
    $.ajax({
      type: "post",
      data: data,
      url: url,
      dataType: "json",
      success: function(d){
        successfn(d);
      },
      error: function(e){
        errorfn(e);
      }
    });
  };



});

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

瓮安县| 阿拉善盟| 稷山县| 大荔县| 长乐市| 融水| 浦北县| 丰都县| 东兴市| 万盛区| 黄龙县| 古丈县| 湘潭市| 湖南省| 都昌县| 牙克石市| 张家口市| 西盟| 兰坪| 黔江区| 开原市| 卓尼县| 西昌市| 宿松县| 辽中县| 夏河县| 新干县| 化德县| 冷水江市| 庄河市| 双桥区| 徐水县| 浏阳市| 台南县| 仁化县| 屯门区| 衡东县| 弥渡县| 长子县| 东山县| 安康市|