zoukankan      html  css  js  c++  java
  • 封装jquery的ajax

     1 <!DOCTYPE html>
     2 <html>
     3 <head>
     4     <meta charset="UTF-8">
     5     <title>jquery ajax封装</title>
     6     <script src="jquery.min.js"></script>
     7 </head>
     8 
     9 <body>
    10     <script>
    11     $(function() {
    12         /**
    13          * ajax封装
    14          * url 发送请求的地址
    15          * data 发送到服务器的数据,数组存储,如:{"username": "张三", "password": 123456}
    16          * succCallback 成功回调函数
    17          * errorCallback 失败回调函数
    18          * type 请求方式("POST" 或 "GET"), 默认已经设置为 "POST"
    19          * dataType 预期服务器返回的数据类型,常用的如:xml、html、json、text
    20          * reference jquery-1.7.1.js
    21          */
    22 
    23         //插入loading
    24         /*var html = "";
    25         html += '<div class="js_loading">';
    26         html += '<div class="mask"></div>';
    27         html += '<div class="loading">';
    28         html += '<span><img src="loading.gif"></span>';
    29         html += '</div>';
    30         html += '</div>';
    31         $("body").append(html);*/
    32 
    33         function $ajax(url, postData, succCallback, errorCallback, type, dataType) {
    34             var type = type || "post";
    35             var dataType = dataType || "json";
    36             $.ajax({
    37                 type: type,
    38                 url: url,
    39                 data: postData,
    40                 dataType: dataType,
    41                 beforeSend: function() { //开始loading
    42                     //$(".js_loading").show();
    43                 },
    44                 success: function(res) {
    45                     /*if (res.success) {
    46                         if (succCallback) {
    47                             succCallback(res);
    48                         }
    49                     } else {
    50                         if (errorCallback) {
    51                             errorCallback(res);
    52                         }
    53                     }*/
    54                 },
    55                 complete: function() { //结束loading
    56                     //$(".js_loading").remove();
    57                     //$(".js_loading").hide();
    58                 }
    59             });
    60         }
    61 
    62         var postData = { moduleId: "fb750e3c-808f-4497-bf4a-f6bf6726a66e" } || {};
    63         //console.log(postData);
    64 
    65         /*$ajax("http://localhost:6688/AuthorizeManage/ModuleColumn/GetColModel", postData, function(res) {
    66             console.log(res);
    67         }, function(res) {
    68 
    69         }, "GET");*/
    70 
    71     });
    72     </script>
    73 </body>
    74 </html>
    业精于勤荒于嬉,行成于思毁于随
  • 相关阅读:
    Codeforces 872B:Maximum of Maximums of Minimums(思维)
    Codeforces 849A:Odds and Ends(思维)
    洛谷 P2397:yyy loves Maths VI (mode)(摩尔投票算法)
    POJ 3264:Balanced Lineup(区间最值查询ST表&线段树)
    Atcoder ABC137D:Summer Vacation(贪心)
    POJ 3278:The merchant(LCA&DP)
    Codeforces Gym-100985C: MaratonIME plays Nim(交互题&博弈)
    ZOJ 1141:Closest Common Ancestors(LCA)
    浅谈C++运算符重载
    初学c++动态联编
  • 原文地址:https://www.cnblogs.com/qixianchuan/p/11162435.html
Copyright © 2011-2022 走看看