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

来源:互联网 发布:铁矿石持仓数据 编辑:程序博客网 时间:2024/05/24 00:58
Js代码  收藏代码
  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  
  2. Resource interpreted as Script but transferred with MIME type text/html:  

 

Js代码  收藏代码
  1. $(function($){  
  2.       var url = 'http://v.juhe.cn/weather/index';  
  3.       $.ajax(url, {  
  4.         data: {  
  5.           'cityname''襄阳',  
  6.           'dtype''jsonp',  
  7.           'key''xxxx',  
  8.           '_'new Date().getTime()  
  9.         },  
  10.         dataType: 'jsonp',  
  11.         crossDomain: true,  
  12.         success: function(data) {  
  13.           if(data && data.resultcode == '200'){  
  14.             console.log(data.result.today);  
  15.           }  
  16.         }  
  17.       });  
  18.   
  19.       var url2 = 'http://v.juhe.cn/weather/index?callback=?';  
  20.       $.getJSON(url2, {  
  21.         'cityname''北京',  
  22.         'dtype''jsonp',  
  23.         'key''xxxx',  
  24.         '_'new Date().getTime()  
  25.       }, function(data){  
  26.         if(data && data.resultcode == '200'){  
  27.           console.log(data.result.today);  
  28.         }  
  29.       });  
  30.   
  31.       var url3 = 'http://v.juhe.cn/weather/index?callback=?';  
  32.       $.get(url3, {  
  33.         'cityname''澳门',  
  34.         'dtype''jsonp',  
  35.         'key''xxxx',  
  36.         '_'new Date().getTime()  
  37.       }, function(data){  
  38.         if(data && data.resultcode == '200'){  
  39.           console.log(data.result.today);  
  40.         }  
  41.       }, 'json');  
  42.     });  
0 0