`

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');
    });

 

 

若有疑问,请发表评论或添加微信为你解答:

更多实例应用扫码体验:

分享到:
评论
2 楼 qiaolevip 2015-11-20  
js跨域需要后端配合的,若对方使用的jsonp可以直接在前端跨域,若是其他的,需要跨域,要么其后端设置运行跨域,要么你使用代理转发结果给前端。
苦涩..五味..甘甜 写道
这个js跨域,只在前段能否解决啊?

1 楼 苦涩..五味..甘甜 2015-11-20  
这个js跨域,只在前段能否解决啊?

相关推荐

Global site tag (gtag.js) - Google Analytics