2011-02-17 103 views
0

從我的網站加載JSON訂閱源時遇到了一些麻煩。我開始認爲Feed本身有問題,因爲將地址插入各種不同的示例代碼塊似乎並不奏效。JSON無法加載

我試過下面的例子中,與「原產地空沒有被訪問控制允許來源允許」,試圖深鑽通過Chrome的JavaScript控制檯的錯誤時,不斷滿足。有任何想法嗎?

嘗試#1:

<script type="text/javascript"> 
     $().ready(function(){ 
      var url = 'http://www.solidverbal.com/category/clicks?feed=json'; 
      $.get(url, function(data) { 
       // can use 'data' in here... 
      }); 
     }); 

    </script> 

嘗試#2:

<script type="text/javascript"> 
     $.ajax({ 
      type: "POST", 
      url: "http://www.solidverbal.com/category/clicks?feed=json", 
      data: '{}', // your parameter goes here 
      contentType: "application/json; charset=utf-8", 
      dataType: "json", 
      processdata: true, 
      success: function (msg) { 
       loadDetails(msg.d); // msg.d contains the JSON data being returned 
      }, 
      error: function (msg, error, obj) { 
       alert(msg.responseText); 
      } 
     }); 


     function loadDetails(results) { 
      // depending on the data in the JSON object, you can access them using 
      // the syntax results.<propertyname> etc… 
     } 

    </script> 
+2

是solidverbal.com你的域名? – 2011-02-17 23:00:49

回答

1

由於same origin policy限制你不能進行跨域AJAX調用。因此,除非您正在運行此腳本的頁面託管在http://www.solidverbal.com上,否則這將不起作用。作爲一種可能的解決方法,如果遠程域支持它,或者在您的域上提供服務器端腳本作爲您的域和遠程域之間的橋樑,然後對此腳本執行AJAX調用,則可以使用JSONP