原型 Ajax 请求限制?
我正在学习原型 Ajax API。我正在阅读他们的文档,我看到了这个:
请记住,出于安全原因(即防止跨站点 脚本攻击)Ajax 请求只能向相同的 URL 发出 包含 Ajax 请求的页面的协议、主机和端口。一些 浏览器可能允许任意 URL,但您不应依赖支持 为此。
那么这是否意味着我无法从另一个应用程序向一个应用程序的后端发出请求?或者我只是误解了这一点。对于像我这样的 JavaScript 新学习者,我真的很感激一些澄清。谢谢
I am learning about he Prototype Ajax API. I was reading their documentation and I saw this:
Remember that for security reasons (that is preventing cross-site
scripting attacks) Ajax requests can only be made to URLs of the same
protocol, host and port of the page containing the Ajax request. Some
browsers might allow arbitrary URLs, but you shouldn't rely on support
for this.
So does this mean that I can't make requests to a backend of one app from another of my apps? Or am I just misunderstanding this. I would really appreciate some clarification for a new javascript learner, like me. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是相同域来源政策。出于安全原因,这是由网络浏览器强制执行的。
简而言之,如果没有此限制,ajax 请求将允许您代表用户检索任何网页。如果他登录了他的网络邮件,这将允许您阅读他的电子邮件。
看一下 JSONP,用于执行跨域 ajax 请求。 (注意 JSONP 中的 P。)
这似乎为 Prototype 添加了 JSONP 支持:http://dandean。 com/jsonp-for-prototypejs/
This is the same domain origin policy. This is enforced by web browsers, for security reasons.
In short, without this restrictions, ajax requests would allow you to retrieve any web page on the behalf of the user. This would allow you to read his emails if he was logged-in on his webmail.
Take a look at JSONP, for doing cross-domain ajax requests. (Notice the P in JSONP.)
This seems to be adding JSONP support to Prototype: http://dandean.com/jsonp-for-prototypejs/