码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2016-09-19 19:43:13      阅读:881      评论:0      收藏:0      [点我收藏+]

标签:

问题:

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

标签:

原文地址:http://www.cnblogs.com/beiz/p/5886255.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!