如何解决XMLHttpRequest cannot load file~~~~~~~Origin 'null' is therefore not allowed access

    xiaoxiao2022-06-29  36

    今天使用 weiapi 的模拟器调试程序的时候,发现使用jquery的异步方法调用的内容不显示 查看后台报错:

    XMLHttpRequest cannot load http://localhost:22222/api/User/Login?strUser=admin&strPwd=123456. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:11111' is therefore not allowed access.

    解决方法: 在 http://localhost:22222 项目的 Web.config 添加一段

    <!-- Begion js 调用跨域 指定域名Access-Control-Allow-Origin 所有用 *,指定域名 http://www.sample.com --> <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Methods" value="OPTIONS,POST,GET"/> <add name="Access-Control-Allow-Headers" value="x-requested-with,content-type"/> <add name="Access-Control-Allow-Origin" value="*" /> </customHeaders> </httpProtocol> <!-- End js 调用跨域 -->

    转载请注明原文地址: https://ju.6miu.com/read-1125179.html

    最新回复(0)