mui ajax 應用的跨域問題

來源:互聯網
上載者:User

標籤:

1、首先在mui.ajax的error函數裡出現:

  “syntaxerror unexpected token <” 

這樣的錯誤,那麼在 mui.ajax中的type寫成  JSONP 就可以了!

 

2、經過mui的success函數返回的資料 要經過json解析才可以使用:

  解析方法:JSON.parse()或者JSON.stringify()

總代碼如下:

mui.ajax(url,{    dataType:"jsonp",//伺服器返回json格式資料    type:"get",//HTTP請求類型    timeout:10000,//逾時時間設定為10秒;    success:function(data){    /*alert("data是:"+data)*/    var configData=JSON.parse(data);//解析資料 cinfig:OK        wx.config({beta:true,                  //坑:這個很重要,必須配置這個為true,才能調用的硬體API    debug: true, // 開啟偵錯模式,調用的所有api的傳回值會在用戶端alert出來,若要查看傳入的參數,可以在pc端開啟,參數資訊會通過log打出,僅在pc端時才會列印。    appId: configData.appId, // 必填,公眾號的唯一標識    timestamp: configData.timestamp, // 必填,產生簽名的時間戳記    nonceStr: configData.nonceStr, // 必填,產生簽名的隨機串    signature: configData.signature,// 必填,簽名,見附錄1jsApiList: []                });    },    error:function(xhr,type,errorThrown){        //異常處理;        alert("錯誤:"+errorThrown);    }});    

  代碼中:wx.config({})是瀏覽器配置,是解析資料的應用示範~

 

mui ajax 應用的跨域問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.