I have a simple .ajax post to a rails scaffold project running on Heroku:
<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>
As it turns out using the javascript console in Chrome I get:
XMLHttpRequest cannot load http://herokuServer/images.json. Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin.
HOWEVER, when I go to the rails app on heroku a new record has been created with the name => “johngalt1”. From everything I’ve read I thought the cross-domain issue with javascript would have prevented the record being created and required me to use json-p or CORS? Or does the javascript cross-domain issue only prevent receiving data from a server via javascript?
It only prevents the browser from receiving data. So if you don’t need a response from this post, you should be ok.
edit – when I’m developing locally, I create a rewrite rule for the Apache2 server on my mac to get around this limitation. it creates a reverse proxy that tricks the browser into allowing cross-domain requests.