標籤:
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 應用的跨域問題