使用Jquery想api接口POST数据时发生如下错误:
XMLHttpRequest cannot load http://localhost:53380/api. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access.
解决方法如下:
在数据接受api的配置文件中的<system.webServer>节点下增加如下节点:
<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>