jQuery 跨域訪問的三種方式 No 'Access-Control-Allow-Origin' header is present on the reque

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.     });  
發佈了40 篇原創文章 · 獲贊 20 · 訪問量 14萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章