XMLHttpRequest cannot load http://192.168.2.85:9888/interface/GetPaidInfo.ashx. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:14527' is therefore not allowed access.---------192.168.2.85是另外一台电脑
一开始找不到问题的原因,后来网上搜到一篇文章http://blog.csdn.net/fdipzone/article/details/46390573 看到相关的错误信息,但是是php的,我用得是aspx,所以做一个测试,我只能用自己的电脑,所以在iis上发布了,然后运行的我的代码
<script type="text/javascript">
function mysubmit() {
// ?CustomerID=001&OMSID=9e6a7949-e9f1-49c3-be10-f1cff55af5d1&Code=3fca8bd2-119c-484a-a582-24f6e41fb279
// http: //192.168.2.85:9888
// http://192.168.2.53:88/Default.aspx
$.ajax({
type: "post",
url: "http://192.168.2.53:88/interface/GetPaidInfo.ashx",
dataType: "json",
success: function(result) {
alert(result.Result.errorCode);
},
error: function(errorThrown) {
alert(errorThrown.responseText);
}
});
}
</script>
控制台报的错误是一样
XMLHttpRequest cannot load http://192.168.2.53:88/interface/GetPaidInfo.ashx. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:14527' is therefore not allowed access.
仿照看到的文章,我在我的服务器文件里 GetPaidInfo.ashx 添加 context.Response.AddHeader("Access-Control-Allow-Origin", "*");
然后重新测试就可以了。至于另外一台机器还没有测试过,有机会测试一下。再次感谢文章的作者傲雪星枫。