如何解决此错误
How can i resolve this error
我正在尝试使用AJAX调用WCF服务,下面是我的代码:
$.ajax({
url: "http://localhost/TestingServices/Service1.svc/GetData"
data: "{'value:1}",
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(data) {
alert(data);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
但在执行后,它给了我以下错误:
XMLHttpRequest cannot load
http://localhost/TestingServices/Service1.svc/GetData.Response to
preflight request doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on
the requested resource. Origin 'null' is therefore not
allowed access. The response had HTTP status code 404.
有人能帮我解决这个问题吗?
尝试在服务项目的web.config中添加2个HttpProtocols
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
</customHeaders>
</httpProtocol>
</system.webServer>
请尝试这个。。。。
$.ajax({
type: "GET",
url: "http://localhost/TestingServices/Service1.svc/GetData",
dataType: "jsonp",
success: readData(data),
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
})
相关文章:
- 测试Angular Service解决错误回调中的promise
- 如何解决Access Control Allow Origin错误
- 如何解决这种情况下的非法调用类型错误
- 如何解决“;错误所请求的URL返回500-内部服务器错误”;
- 可以't解决Javascript错误
- 如何解决此错误
- 我使用了replace(“[^-A-Za-z0-9()%.],但它为'我可以解决这个错误吗
- 我该如何解决“;未捕获引用错误:谷歌没有定义"?(谷歌地图API)
- 我该如何解决这个问题?“未捕获的类型错误:无法读取 null 的属性'appendChild'”
- 闭包编译器--调试解决了我的错误
- 使用SeleniumWebdriver将文本复制到文件时出现编译错误的解决方案
- 如何解决node.js的ENOENT错误
- 找不到以下错误的解决方案
- 解决节点中的“本地主机意外关闭连接”错误
- JavaScript/HTML 错误的解决方案
- 如何解决将值传递给javascript函数时的错误
- React,Flux,React路由器调度错误-可能的批更新解决方案
- windows中的Javascript巨大日期错误..解决方案
- 安卓浏览器触端事件错误解决方法
- 如何将誓言令牌推送到本地存储或本地会话并监听存储事件?(SoundCloud Php/JS 错误解决方法)