MUI AJAX Raw請求資料

來源:互聯網
上載者:User

標籤:

提交介面資料,介面方提供的是post請求,body - raw ; 

我嘗試過JQuery ajax raw 的方式,但是始終無法成功

然後我回想到我用的是mui我就開始考慮用mui.ajax結果就成功了,特此記錄下。其實也是也是自己走了彎路,本來用mui,最好的還是用它的全部東東

代碼分享一下:

 

 1 (function () { 2      3     window.ax = { 4         api:"http://127.0.0.1/",  // 這裡需要替換為你的介面IP 5          6         // GET   提交方式 7         // u    --請求地址   8         // f    --回呼函數   成功 function(data){} ; 失敗 function(xhr,type,errorThrown){} 9         g:function(u,f){10             mui.get( ax.api + u,{},f,"json");11         },12         13         // POST   提交方式14         // u    --請求地址  15         // p    --發送資料   $(id) 例子: "#id",{id:1}16         // f    --回呼函數   成功 function(data){} ; 失敗 function(xhr,type,errorThrown){}17         p:function(u,p,f) {18             if(typeof(p) === "string") {19                 p = $(p).serializeObject();20             }21             mui.ajax(ax.api + u,{22                     data: p,23                     dataType: ‘json‘,24                     type: ‘post‘,25                     headers: {‘Content-Type‘:‘application/json‘},                  26                     success: f,27                     error: f28             });29         }30     }31     32 })();33 34 // 對Date的擴充,將 Date 轉化為指定格式的String35 // 月(M)、日(d)、小時(h)、分(m)、秒(s)、季度(q) 可以用 1-2 個預留位置, 36 // 年(y)可以用 1-4 個預留位置,毫秒(S)只能用 1 個預留位置(是 1-3 位的數字) 37 // 例子: 38 // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 39 // (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18 40 Date.prototype.Format = function (fmt) { //author: zhengsh 2016-9-5 41     var o = {42         "M+": this.getMonth() + 1, //月份 43         "d+": this.getDate(), //日 44         "h+": this.getHours(), //小時 45         "m+": this.getMinutes(), //分 46         "s+": this.getSeconds(), //秒 47         "q+": Math.floor((this.getMonth() + 3) / 3), //季度 48         "S": this.getMilliseconds() //毫秒 49     };50     if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));51     for (var k in o)52     if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));53     return fmt;54 }55 56 // 表單對象轉換為JSON57 $.fn.serializeObject = function() {58     var o = {};59     var a = this.serializeArray();60     $.each(a, function() {61         if(o[this.name]) {62             if(!o[this.name].push) {63                 o[this.name] = [o[this.name]];64             }65             o[this.name].push(this.value || ‘‘);66         } else {67             o[this.name] = this.value || ‘‘;68         }69     });70     return o;71 };

 

MUI AJAX Raw請求資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.