首页 > 技术文章 > JQuery POST请求封装

xjbBill 2017-08-08 15:04 原文

 1 _uri_api = function(url){
 2     return 'http://localhost/msquare/' + url; 
 3 //    return 'http://test2.msqsoft.net:8080/msquare/' + url; 
 4 }
 5 
 6 function post(url, data, callback) {
 7     $.ajax({
 8         beforeSend: function(reqObj, settings) {
 9 //            reqObj.setRequestHeader('Token', '73d42c6777d97d425ea3cca00087f2be76utMnRR');
10         },
11         type: "POST",
12         crossDomain:true,
13         data: data,
14         url: url,
15         dataType: "json",
16         error: function(resObj, textStatus, errorThrown) {
17             data.code = -1;
18             callback(data, resObj.responseText);
19         },
20         success: function(data, textStatus, resObj) {
21             callback(data, resObj.responseText);
22         }
23     });
24 }
25 
26 
27 var api = {
28      personalInfo: {
29          // 添加个人信息
30          add:function(data, func) {
31              post(_uri_api('wx/personal/addSetUpMassage'), data, func);
32          },
33          // 修改
34          update:function(data, func) {
35              post(_uri_api('wx/personal/editSetUpMassage'), data, func);
36          },
37          // 删除
38          del:function(data, func) {
39              post(_uri_api('wx/personal/deleteSetUpMassage'), data, func);
40          }
41      }
42 };

推荐阅读