Jquery 的POST方法调用别的服务器上的WebService 会出现跨域的问题
解决方法:cors的跨域资源共享方案
web.config 设置如下:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off"/>
<webServices>
<protocols>
<add name="HttpSoap"/>
<add name="HttpPost"/>
<add name="HttpGet"/>
<add name="Documentation"/>
</protocols>
</webServices>
</system.web>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Methods" value="POST,GET"/>
<add name="Access-Control-Allow-Headers" value="x-requested-with,content-type"/>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>2. jquery 设置一下cors 支持为true
$.support.cors = true;

本文介绍如何通过配置web.config文件启用CORS跨域资源共享,以解决使用JQuery进行POST请求时遇到的跨域问题。同时展示了如何在JQuery中设置支持CORS。
1005

被折叠的 条评论
为什么被折叠?



