2011-01-27 47 views
2

假設我有一個YQL查詢像這樣(其實,這是我使用的精確查詢):爲什麼我的YQL查詢在jQuery控制檯返回空值,而同一個YQL查詢在YQL控制檯返回正值?

select * from xml where url="http://blog.artbeads.com/feed/" 
        and itemPath="//rss/channel/item" 

Run this query on the YQL Console,它應該返回10個項目。

現在考慮下面的jQuery(這幾乎是我使用的生產,除了成功的呼叫確切的代碼,但我不相信這是一個重要的因素):

// Working example at http://jsbin.com/ekomi4 
$.ajax({ 
    url: 'http://query.yahooapis.com/v1/public/yql', 
    dataType: 'jsonp', 
    data: { 
    q: 'select * from xml where url="http://blog.artbeads.com/feed/" and itemPath="//rss/channel/item"', 
    format: 'json' 
    }, 
    success: function(content) { $('#content').text(JSON.stringify(content, null, ' ')) } 
}) 

上述代碼沒有按預期執行:返回JSON對象(如預期的那樣),但是query.results = null(意外)。

+0

嘗試使用curl -v或wget獲取關於請求的調試信息 – 2013-11-12 20:05:03

回答

0

我跟着jsbin鏈接,並且在Windows上運行的Chrome中一切正常。您應該驗證當前瀏覽器實際上是否支持JSON.stringify方法,如果不支持,請使用庫(https://github.com/douglascrockford/JSON-js/)。

+0

爲了清楚起見,我已經更新了原始問題,它與`JSON.stringify`的功能無關,而是由`$ .ajax()`調用。無論如何,感謝您的評論。 – gibson 2011-01-27 01:11:50