如何通过回调函数传递参数来搜索 Yahoo BOSS 和 BING 等 API?
我正在使用 Yahoo BOSS 和 Bing API 为我的网站提供搜索功能。具体来说,我使用他们的 JSON 响应格式,将回调函数传递给搜索提供程序,该函数稍后将随搜索结果一起回调。我的回调函数实际上被调用,但问题是,如果我一次发出多个请求,我无法判断某个响应是针对哪个请求的。为此,有没有办法将回调函数的附加参数传递给搜索提供程序,以便我稍后可以使用它来识别哪个响应与哪个请求相关? 谢谢
I am using Yahoo BOSS and Bing APIs to provide search functionality to my site. Specificaly, I use their JSON response formats where I would pass a callback function to the search provider that would later be called back with the search results. My callback function actually gets called, but the problem is, if I make more than one requests at a time, I can't tell which request a certain response is for. To this end, is there a way to pass additional parameters with the callback function to the search provider so that I can later use it to identify which response goes with which request?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我和你有同样的问题!我用谷歌搜索并找到了一些解决方案
我已经解决了我的问题。现在我向您展示它,希望它可以帮助您:)
之前的代码:
function GeocodeCallback(result) {.. to do with result callback, -->我想在这里添加一些 pin 信息}
因为每个 sccipt 添加到文档 ( document.body.appendChild(script);) 时都会运行 -->和回调,你不能添加更多参数。
我通过ajax请求解决它(不再添加到文档中),当ajax调用成功时 -->我调用 GeocodeCallback(result, pin)
这是完整的代码。
I have a same problem with you! I googled and find some solutions
and I has solve my problem. Now i show it to you, I hope it can help you :)
Previous code:
function GeocodeCallback(result) {.. to do with result callback, --> i want to add some pin infomation here}
Because each sccipt when add to document ( document.body.appendChild(script);) it will be run --> and callback, you cant add more params.
I solve it by request through ajax (doesnt add to document any more), when the ajax call success --> I call the GeocodeCallback(result, pin)
Here is the complete code.