自學(xué)微信小程序,用小程序做了個小項目,踩了一些坑:
坑一:
Navigated to http://1755603039.appservice.open.weixin.QQ.com/appserviceVM2507:1 Sat Feb 04 2017 21:46:27 GMT+0800 (中國標(biāo)準(zhǔn)時間) 渲染層錯誤VM2507:2 SyntaxError: Invalid or unexpected token(anonymous) @ VM2507:2VM2509:1 Sat Feb 04 2017 21:46:27 GMT+0800 (中國標(biāo)準(zhǔn)時間) 渲染層錯誤VM2509:2 webviewScriptErrorInvalid or unexpected tokenSyntaxError: Invalid or unexpected token(anonymous) @ VM2509:2VM2510:1 Sat Feb 04 2017 21:46:27 GMT+0800 (中國標(biāo)準(zhǔn)時間) 渲染層錯誤VM2510:2 Uncaught SyntaxError: Invalid or unexpected token(anonymous) @ VM2510:2VM2511:1 Sat Feb 04 2017 21:46:27 GMT+0800 (中國標(biāo)準(zhǔn)時間) 渲染層錯誤VM2511:2 ReferenceError: $gwx is not defined at 1755603039.debug.open.weixin.qq.com/pages/index/index.html:1438(anonymous) @ VM2511:2VM2512:1 Sat Feb 04 2017 21:46:27 GMT+0800 (中國標(biāo)準(zhǔn)時間) 渲染層錯誤VM2512:2 webviewScriptError$gwx is not definedReferenceError: $gwx is not defined at http://1755603039.debug.open.weixin.qq.com/pages/index/index.html:1438:27(anonymous) @ VM2512:2VM2513:1 Sat Feb 04 2017 21:46:27 GMT+0800 (中國標(biāo)準(zhǔn)時間) 渲染層錯誤VM2513:2 Uncaught ReferenceError: $gwx is not defined出現(xiàn) $gwx is not defined
提示報錯位置 at http://1755603039.debug.open.weixin.qq.com/pages/index/index.html:1438:27
這個報錯位置提示沒有任何意義,因為index.whtml我好幾天沒有動過了;
這個錯誤后來發(fā)現(xiàn) 在剛改過的whtml 頁面 想寫"¥{{user.salary}}/時 " 結(jié)果寫成了"${{user.salary}}/時" , 將 ¥ 寫成了$;
坑二
封裝了一下微信提供的網(wǎng)絡(luò)訪問接口,結(jié)果服務(wù)器端死活獲取不到傳遞的參數(shù),最后上網(wǎng)一查,post請求的header必須將content-type設(shè)置為 'application/x-www-form-urlencoded',否則后臺就接收不到數(shù)據(jù),而我設(shè)置的是'application/json' ,沒有其它原因,因為我就是想傳遞json數(shù)據(jù)啊,另外POST必須要大寫,這點接口文檔上寫了,正確代碼如下:
function request(param) { var obj ={ url: param.url, header: { 'content-type': 'application/x-www-form-urlencoded', /****注意:post方式必須這樣設(shè)置,否則后臺獲取不到參數(shù) */ /***'content-type': 'application/json',**/ }, method:'POST',/***注意post必須大寫 */ data:param.data==undefined ? "":param.data, success: function( res ) { /**console.log(res.data); */ if(param.success && typeof(param.success) =="function" ){ param.success(res); } }, fail: function( res ) { if(param.fail && typeof(param.fail) =="function" ){ param.fail(res); } } } if(app.globalData.token){ obj.header.access=app.globalData.token; } /** console.log( obj.url) console.log(JSON.stringify(obj.data) ); */ wx.request(obj); }
新聞熱點
疑難解答