我正在尝试使用javascript访问.net webservice,但却给出了以下错误:
交叉源请求仅支持协议方案:http,数据,chrome,chrome-extension,https,chrome-extension-resource。
这是java脚本代码:
var v = {"name":"zain",
"password":"abc"
}
// alert("wat");
$.ajax({
type: "POST",
url: "webcare.azurewebsites.net/WCService.asmx/GetParent",
data: JSON.stringify(v),
contentType: "application/x-www-form-urlencoded",
dataType: "json",
success: OnSuccess,
error: OnError
});
}
function OnSuccess(data, status)
{
alert("success: "+data.d);
}
function OnError(request, status, error)
{
alert("error: "+request.statusText);
}
根据一个解决方案,该解决方案表示在我的web服务旁边添加了clientaccesspolicy.xml文件,但它仍然给出了同样的错误。 这是我在clientaccesspolicy.xml中添加的代码
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="SOAPAction">
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
答案 0 :(得分:0)
您还需要在适当的位置https://msdn.microsoft.com/en-us/library/cc197955%28VS.95%29.aspx拥有跨域xml文件。查找“使用crossdomain.xml文件以允许跨域访问”。按照该文章中的说明进行操作。