【发布时间】:2016-09-09 04:35:40
【问题描述】:
我正在尝试使用 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.
谁能帮我解决这个问题?
【问题讨论】:
-
去掉 contentType: "application/json; charset=utf-8" 然后试试,,,
-
现在,我收到 dis 错误:POST localhost/Wcf/service1.svc/GetData 415(无法处理消息,因为内容类型 'application/x-www-form-urlencoded; charset=UTF-8' 不是预期的输入'text/xml; charset=utf-8'。)
标签: javascript jquery ajax html cordova