【发布时间】:2017-01-28 05:35:41
【问题描述】:
希望将数据从 Ajax 发送到包含方法 GetQuickQuote(string x) 并从 Web 服务返回数据的 Wcf 服务。
jQuery
$('#txtBox').blur(function () {
debugger;
$.ajax({
type: "POST",
url: "http://logicalfire-pc:8090/Libertytest.Service1.svc" + "/GetQuickQuote",
crossDomain: true,
data: JSON.stringify({ x: 'ght'}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (response.d == true) {
alert("You will now be redirected.");
}
},
error:function(eror)
{
alert('failure');
}
})
});
WCF 服务包含
public string GetQuickQuote(string x)
{
var ReadXmlPath = GetApplicationPath() + "TextFile1.txt";
x=ReadXmlPath;
return x;
}
我得到以下回应:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://logicalfire-pc:8090/Libertytest.Service1.svc/GetQuickQuote. (Reason: CORS header 'Access-Control-Allow-Origin' missing).
【问题讨论】: