当前位置:首页 > 开发 > Web前端 > Jquery > 正文

jQuery 跨域访问的三种方式 No 'Access-Control-Allow-Origin' header is present on the reque

发表于: 2014-09-17   作者:qiaolevip   来源:转载   浏览:
摘要: 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
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

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号