Html5+Mui前端框架,开发记录(二):提交不了数据?

1.Mui 请求Webapi接口,返回所需要的数据(get,post)

                  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.但是如果浏览器报错为

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“跨域”,解决办法是:

找到你的Webapi项目—右键选择“管理NuGet程序包”—在浏览的搜索框,搜索下载即可:

 

posted @ 2019-04-22 11:08  Bonnie_W  阅读(445)  评论(0编辑  收藏  举报