前提是接口程序是你自己发布的,也就是你可以在响应中添加header。当web站点请求接口站点的时候,js会提示跨域无法请求。
<span style="font-size: 16px;">HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "http://localhost:9004");//我自己调试的站点</span>
你需要添加响应Header。 这时,你在ie下,会请求到你想要的数据, Chrome,Firfox,Maxthon等等浏览器还是请求文档失败,似乎是没指定请求的内容。
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");//再添加一个header
Success! 也没什么就是加了俩头
<span style="font-size: 16px;">HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "http://localhost:9004");//我自己调试的站点</span>
你需要添加响应Header。 这时,你在ie下,会请求到你想要的数据, Chrome,Firfox,Maxthon等等浏览器还是请求文档失败,似乎是没指定请求的内容。
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");//再添加一个header
Success! 也没什么就是加了俩头