首页 > 代码库 > jQuery 跨域访问的三种方式 No 'Access-Control-Allow-Origin' header is present on the reque
jQuery 跨域访问的三种方式 No 'Access-Control-Allow-Origin' header is present on the reque
问题:
XMLHttpRequest cannot load http://v.xxx.com. No ‘Access-Control-Allow-Origin‘ header is present on the requested resource. Origin ‘http://localhost:63342‘ is therefore not allowed access. test.html:1 Resource interpreted as Script but transferred with MIME type text/html:
解决方案:
$(function($){ var url = ‘http://v.juhe.cn/weather/index‘; $.ajax(url, { data: { ‘cityname‘: ‘襄阳‘, ‘dtype‘: ‘jsonp‘, ‘key‘: ‘xxxx‘, ‘_‘: new Date().getTime() }, dataType: ‘jsonp‘, crossDomain: true, success: function(data) { if(data && data.resultcode == ‘200‘){ console.log(data.result.today); } } }); var url2 = ‘http://v.juhe.cn/weather/index?callback=?‘; $.getJSON(url2, { ‘cityname‘: ‘北京‘, ‘dtype‘: ‘jsonp‘, ‘key‘: ‘xxxx‘, ‘_‘: new Date().getTime() }, function(data){ if(data && data.resultcode == ‘200‘){ console.log(data.result.today); } }); var url3 = ‘http://v.juhe.cn/weather/index?callback=?‘; $.get(url3, { ‘cityname‘: ‘澳门‘, ‘dtype‘: ‘jsonp‘, ‘key‘: ‘xxxx‘, ‘_‘: new Date().getTime() }, function(data){ if(data && data.resultcode == ‘200‘){ console.log(data.result.today); } }, ‘json‘); });
jQuery 跨域访问的三种方式 No 'Access-Control-Allow-Origin' header is present on the reque
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。