标签:ajax post 跨域 wcf restful cross domain post
前段时间做手机WebAPP, 但开发人员习惯在浏览器上先调试基本功能, 但这里就出现了跨域请求问题
当然如果你自己写服务, 自己写WebAPP 都是localhost 就不会跨域, 而且发布到手机上也不会跨域
关键来了!!!!
1. 先要确保你的js写的是对的
$.ajax({ url: url3, data: JSON.stringify({userName:uid,userPass:pwd}), contentType:"application/json; charset=utf-8", type:"POST", crossDomain: true, dataType: 'json', success: function (data) { }, error: function (xhr, textStatus, errMsg) { } });
3. 你的web.config 的 system.webServer 节点需要增加跨域响应支持
<httpProtocol>
<customHeaders>
<addname="Access-Control-Allow-Origin"value="*" />
<addname="Access-Control-Allow-Headers"value="Content-Type" />
<addname="Access-Control-Allow-Methods"value="GET, POST,PUT, DELETE, OPTIONS" />
</customHeaders>
</httpProtocol>
4.这个不知道是不是必须的, 需要在system.serviceModel 中的standardEndpoint增加
crossDomainScriptAccessEnabled="true"
本人花了6个小时才解决,希望其他人少走弯路
Ajax Post Cross Domain 跨域请求 WCF RestFull
标签:ajax post 跨域 wcf restful cross domain post
原文地址:http://blog.csdn.net/gavin_luo/article/details/44855627