我正在学习他的原型(prototype) Ajax API。我在阅读他们的文档时看到了这个:
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.
那么这是否意味着我不能从我的另一个应用程序向一个应用程序的后端发出请求?或者我只是误解了这一点。对于像我这样的新 javascript 学习者,我真的很感激一些澄清。谢谢
最佳答案
这是 same domain origin policy .出于安全原因,这是由 Web 浏览器强制执行的。
简而言之,如果没有这个限制,ajax 请求将允许您代表用户检索任何网页。如果他在他的网络邮件上登录,这将允许您阅读他的电子邮件。
看看JSONP ,用于执行跨域 ajax 请求。 (注意 JSONP 中的 P。)
这似乎是在为 Prototype 添加 JSONP 支持:http://dandean.com/jsonp-for-prototypejs/
关于javascript - 原型(prototype) Ajax 请求限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7295990/