No 'Access-Control-Allow-Origin' header is present on the requested resource

前几天碰到一个问题,开发工具控制台报错:

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", "*");  

然后重新测试就可以了。至于另外一台机器还没有测试过,有机会测试一下。再次感谢文章的作者傲雪星枫。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值