gpt4 book ai didi

javascript - Access-Control-Allow-Origin 不允许 jQuery Ajax POST 到 Rails 3.2.2

转载 作者:行者123 更新时间:2023-11-28 09:55:01 25 4
gpt4 key购买 nike

我有一个简单的 .ajax 帖子到在 Heroku 上运行的 Rails 脚手架项目:

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"> </script>
</head>
<body>
<script>
$(document).ready(function(){
$.ajax({
type: 'POST', url: "http://herokuserver/images.json",
data: { image: { name: "johngalt1" } }
});
});
</script>
</body>

事实证明,在 Chrome 中使用 javascript 控制台我得到:

 XMLHttpRequest cannot load http://herokuServer/images.json. Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin.

但是,当我转到heroku 上的rails 应用程序时,已创建一条名为=>“johngalt1”的新记录。从我读过的所有内容来看,我认为 javascript 的跨域问题会阻止创建记录并要求我使用 json-p 或 CORS?或者javascript跨域问题只是阻止通过javascript从服务器接收数据?

最佳答案

它只是阻止浏览器接收数据。因此,如果您不需要这篇文章的回复,应该没问题。

编辑 - 当我在本地开发时,我为 Mac 上的 Apache2 服务器创建了一个重写规则来绕过此限制。它创建一个反向代理,欺骗浏览器允许跨域请求。

关于javascript - Access-Control-Allow-Origin 不允许 jQuery Ajax POST 到 Rails 3.2.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10212071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com