javascript - 原型(prototype) Ajax 请求限制?

标签 javascript ajax httpwebrequest xmlhttprequest prototypejs

我正在学习他的原型(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/

相关文章:

javascript - Ajax获取方法错误

c# - 如何在 ASP.NET Web API 中记录原始 HTTP 请求,无论它是否路由到 Controller ?

c# - 如何使用 Silverlight GET HttpWebRequest 设置 header ?

javascript - 如何更改 Firebase 父节点的名称以启用规则

javascript - NodeJS 发布请求 - 参数中的数字返回 NaN

javascript - 使用索引访问 AJAX JSON 属性在 promise 中给出未定义

javascript - 如何访问 onreadystatechange 之外的数组(范围问题)

javascript - 如何从传入的函数 var 中分配一个 var?

javascript - 按下按钮时让烟花发射

performance - HTTP 请求成本与页面大小成本?