是否可以中止Google API请求?类似的东西:
req = gapi.client.request({
path: 'youtube/v3/search',
params: {
q: search_query,
type: 'video',
part: 'id,snippet',
maxResults: 8,
fields: 'items(id(videoId),snippet(thumbnails,title))'
})
req.execute(function(result){ console.log(result) })
然后(在请求返回之前)
req.abort()
答案 0 :(得分:0)
我最后通过简单地手工构建XMLHttpRequest(使用jQuery)来实现这一点。这非常容易。
window.current_search = $.ajax('https://content.googleapis.com/youtube/v3/search', {
dataType: 'jsonp',
data: {
q: search_query,
type: 'video',
part: 'id,snippet',
maxResults: 8,
fields: 'items(id(videoId),snippet(thumbnails,title))',
key: apiKey
}
}).done(render_page)
如果我需要取消请求......
window.current_search.abort()
代码甚至不比使用api的版本长得多。