使用跨域Ajax进行搜索?
我意识到同源策略通常会使这成为不可能,但我正在尝试使用 jquery.crossdomainajax.js 创建一个简单的搜索脚本
假设我有 randomwebsite.com。我希望该网站能够运行一个脚本,该脚本将在不同服务器上的另一个网站上搜索单个单词。例如,我希望我的 randomwebsite.com 在 espn.com 中搜索“Yankees”,然后我希望它提醒我是否在外国域网站上找到了该词。
这可能吗?我感谢你们提供的所有帮助!
I realize that the same origin policy would normally make this impossible, but I'm trying to create a simple search script using the jquery.crossdomainajax.js
Say I have randomwebsite.com. I want that website to be able to run a script that will search another site on a different server for a single word. For instance, I would want my randomwebsite.com to search espn.com for "Yankees" and then I would like it to alert me as to whether that word was found on the foreign domain site.
Is this possible? I appreciate all the help you guys can offer!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,这是不可能的。跨站点 ajax 的工作原理是将其他站点作为脚本包含在内。
No it's not possible. Cross site ajax works by including the other site as script.
我不知道有什么方法可以仅使用客户端 Javascript 来做到这一点。
解决此问题的一种方法是拥有一个可以为您进行搜索并通过 ajax 调用将结果返回给您的服务器。因此,您在 randomwebsite.com 上的网页将发出 ajax 调用,以便您的 randomwebsite.com 服务器。该服务器将在 espn.com 中搜索该单词,并在 ajax 调用中将结果返回给您。您的服务器不会有任何同源限制。
I don't know of a way to do this with client-side Javascript only.
One way to solve this problem is to have a server that can do the searching for you and return the results to you via an ajax call. So, your webpage on randomwebsite.com would issue an ajax call so your randomwebsite.com server. That server would search espn.com for the word and return the results back to you in the ajax call. Your server would have none of the same origin limitations.