我正在尝试进行一个简单的测试而不更改涉及跨域AJAX调用的任何服务器端代码,我想知道是否可以再使用它--disable-web-security.它似乎无法在Chrome 28上运行.
自Chrome版本21以来我没有使用它; 这个功能被删除了吗?
我创建了一个phonegap应用程序,我正在调用WCF服务,该服务位于nopCommerce插件中.
我在发送api请求时遇到以下错误:
跨源请求已阻止:同源策略禁止在http://testwebsite.com/Plugins/NopRestApi/RemoteService/WebService.svc/GetData上读取远程资源.(原因:CORS预检频道没有成功).
跨源请求已阻止:同源策略禁止在http://testwebsite.com/Plugins/NopRestApi/RemoteService/WebService.svc/GetData上读取远程资源.(原因:CORS请求失败).
使用Ajax进行API调用
$.ajax({
crossDomain: true,
type: "POST",
contentType: "application/json",
async: false,
url: "http://testwebsite.com/Plugins/NopRestApi/RemoteService/WebService.svc/GetData",
data: "{storeId:" + storeId + ", languageId:" + languageId + ", customerId:" + customerId + "}",
//data: { storeId: storeId, languageId: languageId, customerId: customerId },
dataType: 'json',
//jsonp: false,
success: function (data) {
alert(data.d);
},
error: function (xhr, textStatus, error) {
alert("Error! " + error);
}
});
Run Code Online (Sandbox Code Playgroud)
我通过谷歌的一些研究在我的Web.config文件中添加了以下内容.
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
</customHeaders>
</httpProtocol> …Run Code Online (Sandbox Code Playgroud)