为了使用jQuery创建跨域AJAX请求,我正在尝试使用YQL RSS。
select * from rss where url='https://www.top1000funds.com/feed/most-popular-posts/'
我的代码:
var feed = "https://www.top1000funds.com/feed/most-popular-posts/";
var yql = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20rss%20where%20url%3D%22"+encodeURIComponent(feed)+"%22&format=json&diagnostics=true&callback=&rnd=_"+event.timeStamp;
console.log(yql);
$.getJSON(yql, function(res) {
var html = '<div class="feedListWrap">';
if(res.query && res.query.results && res.query.results.item){
//code goes here
} else {
html += '<div class="feedEmpty">The feed is currently not available due to server issues. Check back soon!</div>';
}
html += '</div>';
rssWrap.append(html);
}, "jsonp");
&#13;
它运行正常,但现在我在json响应上遇到Bad Request问题而没有错误的文字说明:
{"query":{"count":0,"created":"2017-08-25T03:09:09Z","lang":"en","diagnostics":{"publiclyCallable":"true","url":{"execution-start-time":"0","execution-stop-time":"2","execution-time":"2","http-status-code":"400","http-status-message":"Bad Request","content":"https://www.top1000funds.com/feed/most-popular-posts/"},"user-time":"2","service-time":"2","build-version":"2.0.164"},"results":null}}
您可以使用网址查询进行测试:link
尝试检查YQL控制台时,它可以正常工作:
{
"query": {
"count": 10,
"created": "2017-08-25T02:54:38Z",
"lang": "en-US",
"diagnostics": {
"publiclyCallable": "true",
"url": {
"execution-start-time": "1",
"execution-stop-time": "8",
"execution-time": "7",
"content": "https://www.top1000funds.com/feed/most-popular-posts/"
},
"user-time": "8",
"service-time": "7",
"build-version": "2.0.164"
},
"results": {
"item": [
{
"title": "OTPP’s private equity revolution",
"link": "https://www.top1000funds.com/profile/2017/08/03/otpps-private-equity-revolution/",
"pubDate": "Thu, 03 Aug 2017 06:39:33 +0000",
"creator": "Sarah Rundell",
"guid": {
"isPermaLink": "false",
"content": "http://www.top1000funds.com/?p=17673"
},
"description": "<div class=\"feedThumb\"><img width=\"125\" height=\"125\" src=\"https://dmmn26wgpgtie.cloudfront.net/wp-content/uploads/2017/08/03163918/jane-rowe_700px-125x125.jpg\" class=\"attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" srcset=\"https://dmmn26wgpgtie.cloudfront.net/wp-content/uploads/2017/08/03163918/jane-rowe_700px-125x125.jpg 125w, https://dmmn26wgpgtie.cloudfront.net/wp-content/uploads/2017/08/03163918/jane-rowe_700px-150x150.jpg 150w\" sizes=\"(max-width: 125px) 100vw, 125px\" /></div><div class=\"feedExcerpt\">A deep dive into the world-class private capital division of OTPP, led by Jane Rowe, reveals a strategy of buying large direct stakes in companies, and a commitment to innovation.</div>",
"encoded": "<div class=\"feedThumb\"><img width=\"125\" height=\"125\" src=\"https://dmmn26wgpgtie.cloudfront.net/wp-content/uploads/2017/08/03163918/jane-rowe_700px-125x125.jpg\" class=\"attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" srcset=\"https://dmmn26wgpgtie.cloudfront.net/wp-content/uploads/2017/08/03163918/jane-rowe_700px-125x125.jpg 125w, https://dmmn26wgpgtie.cloudfront.net/wp-content/uploads/2017/08/03163918/jane-rowe_700px-150x150.jpg 150w\" sizes=\"(max-width: 125px) 100vw, 125px\" /></div><div class=\"feedExcerpt\">A deep dive into the world-class private capital division of OTPP, led by Jane Rowe, reveals a strategy of buying large direct stakes in companies, and a commitment to innovation.</div>"
},
{
"title": "The value of the Canadian model",
"link": "https://www.top1000funds.com/analysis/2017/08/08/the-value-of-the-canadian-model/",
"pubDate": "Tue, 08 Aug 2017 04:53:00 +0000",
"creator": "AMANDA WHITE",
"guid": {
"isPermaLink": "false",
"content": "http://www.top1000funds.com/?p=17681"
},
"description": "<div class=\"feedThumb\"><img width=\"125\" height=\"125\" src=\"https://dmmn26wgpgtie.cloudfront.net/wp-content/uploads/2016/03/22215806/Keith-Ambachtsheer-Head_Shoulders_Jan-700x500-2016-125x125.jpg\" class=\"attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" srcset=\"https://dmmn26wgpgtie.cloudfront.net/wp-content/uploads/2016/03/22215806/Keith-Ambachtsheer-Head_Shoulders_Jan-700x500-2016-125x125.jpg 125w, https://dmmn26wgpgtie.cloudfront.net/wp-content/uploads/2016/03/22215806/Keith-Ambachtsheer-Head_Shoulders_Jan-700x500-2016-150x150.jpg 150w\" sizes=\"(max-width: 125px) 100vw, 125px\" /></div><div class=\"feedExcerpt\">A lot has been written about the superiority of the “Canadian model” for managing pensions, but can a value be assigned to this organisational design structure? </div>",
"encoded": "<div class=\"feedThumb\"><img width=\"125\" height=\"125\" src=\"https://dmmn26wgpgtie.cloudfront.net/wp-content/uploads/2016/03/22215806/Keith-Ambachtsheer-Head_Shoulders_Jan-700x500-2016-125x125.jpg\" class=\"attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" srcset=\"https://dmmn26wgpgtie.cloudfront.net/wp-content/uploads/2016/03/22215806/Keith-Ambachtsheer-Head_Shoulders_Jan-700x500-2016-125x125.jpg 125w, https://dmmn26wgpgtie.cloudfront.net/wp-content/uploads/2016/03/22215806/Keith-Ambachtsheer-Head_Shoulders_Jan-700x500-2016-150x150.jpg 150w\" sizes=\"(max-width: 125px) 100vw, 125px\" /></div><div class=\"feedExcerpt\">A lot has been written about the superiority of the “Canadian model” for managing pensions, but can a value be assigned to this organisational design structure? </div>"
},
...
]
}
}
}
请问任何建议?
答案 0 :(得分:1)
我认为这是来自Yahoo YQL端的问题,与使用的代码或其他内容无关。 如果刷新查询,他随机加载错误或罚款。
我认为我们(用户)无能为力。 雅虎需要解决这个问题......
答案 1 :(得分:0)
我遇到了完全相同的问题。我的代码有点不同,但原理是一样的 - 我正在通过YQL运行RSS提要以解决跨域问题..它工作正常,直到昨天但它现在返回相同的错误请求错误,但是,查询我每次都在YQL控制台中使用工作。
我能找到的唯一可行解决方案是:jQuery with YQL RSS Feeds randomly returning null
它表明它可能与YQL控制台上没有的API超时有关。
如果有人能够证实这一点或提供其他可能性,我也想听听他们的意见。
答案 2 :(得分:0)
当我在YQL控制台上试用时,它会缓存结果,我相信。如果你进入调试模式,它不会使用计算结果,所以你会更好地看到任何问题。
答案 3 :(得分:0)
从我这边看,自2天以来一切运作良好。