ASP.NET Ajax 跨域问题解决方案

通过设置Access-Control-Allow-Origin来实现跨域。

例如:客户端的域名是client.runoob.com,而请求的域名是server.runoob.com。

如果直接使用ajax访问,会有以下错误:

XMLHttpRequest cannot load http://server.runoob.com/server.php. No 'Access-Control-Allow-Origin' header is present on the requested resource.Origin 'http://client.runoob.com' is therefore not allowed access.
添加如下代码在ashx中
Response.AppendHeader("Access-Control-Allow-Origin", "*")
Response.AppendHeader("Content-type", "application/json")

AJAX跨域问题

09-27

为什么在谷歌和FF浏览器能正常加载但是在搜狗就提示跨域问题要求在header加代码呢?rn $.ajax(rn url:"http://www.tvku.com/lifeshop.html?page=1&job=lifeshop&ajax=1",rn type:"GET",rn dataType : "json",rn success: function(data)rn var list=data.data.list;rn html="";rn for(var i=0;i "+list[i].name+" "+list[i].introduction+" 地 址:"+list[i].address+"查看地图 电 话:"+list[i].tel+" 营业时间:10:00-21:00 推 荐:"+list[i].recommend+" 收藏"; rn rn rn rn $('.lifeshop-content').html(html);rn rn rn )rnrnrnrn这是后台数据rnrn"msg":"\u83b7\u53d6\u6210\u529f","error":0,"data":"list":["shopid":"59","recommend":"0","name":"\u6587\u5316","pinyin":"S a s s","type":"1","trade":"7_93","groupid":"0","hit":"336","visitor":"324","visittime":"1474935224","pcat":"0","ccat":"0","tid":"0","status":"3","areaid":"0","tel":"","fax":"","thumb":"http:\/\/www.tvku.com\/attachment\/images\/20160823\/1652559113.jpeg","mode":"","business":"","template":"appdefault","app_template":"","sell":"","buy":"","contacts":"","address":"\u6e56\u5317_Sassafras","postcode":"","citycode":"0","email":"","qq":"839727249","licence_photo":"","licence":"","nopass":"","longitude":"","latitude":"","city":"","introduction":"","shopid":"58","recommend":"0","name":"\u76f1\u7719","pinyin":"hao xiang gou","type":"2","trade":"3_38","groupid":"21","hit":"199","visitor":"192","visittime":"1474313173","pcat":"0","ccat":"0","tid":"5","status":"1","areaid":"0","tel":"","fax":"","thumb":"http:\/\/www.tvku.com\/attachment\/images\/20160822\/1653298556.jpg","mode":"","business":"","template":"appdefault","app_template":"appdefault","sell":"","buy":"","contacts":"","address":"\u5e7f\u4e1c\u7701\u4f5b\u5c71\u5e02\u7985\u57ce\u533a\u6f9c\u77f3\u4e8c\u8def","postcode":"","citycode":"0","email":"","qq":"","licence_photo":"attachment\/images\/20160822\/1656304906.jpg","licence":"","nopass":"","longitude":"","latitude":"","city":"","introduction":""]

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试