1.Mui 請求Webapi接口,返回所須要的數據(get,post)ajax
mui.ajax({ url: getAddress() + '/api/Qiliu/get?jsoncallback=?', data: {}, async: false, dataType: 'json', crossDomain: true, //強制使用5+跨域 type: 'get', timeout: 10000, success: function(data) { //xxx邏輯 } });
mui.ajax({ url: getAddress() + '/api/Kedan/Post?jsoncallback=?', data: { DailisId: Id, GukeName: name.value, GukePhone: phone.value, Xfxm: xfxm.value, HId: zxyy.tabIndex, Money: xfmoney.value, CTime: startdate.value, Remark: textarea.value, Pzimg:fd }, async: true, dataType: 'json', crossDomain: true, //強制使用5+跨域 type: 'post', timeout: 10000, success: function(data) { mui.alert('提交成功!', '提示'); name.value = ""; phone.value = ""; xfxm.value = ""; xfmoney.value = ""; startdate.value = ""; textarea.value = ""; var s = document.getElementById('imgs'); s.innerHTML=""; }, error: function(xhr, type, errorThrown) {} });
2.可是若是瀏覽器報錯爲json
1 Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8020' is therefore not allowed access. The response had HTTP status code 403.錯誤。
致使請求不到、提交不了數據。很大一部分緣由是Webapi「跨域」,解決辦法是:api
找到你的Webapi項目—右鍵選擇「管理NuGet程序包」—在瀏覽的搜索框,搜索下載便可:跨域