【问题标题】:Why does my YQL query return a null result in jQuery while the same YQL query returns positive at the YQL console?为什么我的 YQL 查询在 jQuery 中返回空结果,而相同的 YQL 查询在 YQL 控制台上返回正数?
【发布时间】:2011-01-27 00:59:35
【问题描述】:

假设我有一个这样的 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(意外)。

【问题讨论】:

  • 尝试使用 curl -v 或 wget 获取有关请求的调试信息

标签: jquery ajax json yql


【解决方案1】:

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

【讨论】:

  • 为了清楚起见,我更新了原始问题,这与JSON.stringify 的功能无关,而是$.ajax() 调用返回的内容。无论如何,感谢您的评论。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多