为什么我的YQL查询在jQuery中返回null结果,而同样的YQL查询在YQL控制台返回正数?

时间:2011-01-27 00:59:35

标签: jquery ajax json 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(意外)。

1 个答案:

答案 0 :(得分:0)

我按照jsbin链接,在Windows上运行的Chrome中一切正常。您应该验证当前浏览器是否实际支持JSON.stringify方法,如果不支持,请使用库(https://github.com/douglascrockford/JSON-js/)。

相关问题