I'm setting up an API for a simple webservice and stumbled upon a problem. I use Ruby on Rails for the back end and a JQuery ajax call to send a POST to create an instance of a model. The JavaScript code is:
$.ajax({
type: "POST",
url: "http://localhost:3000/api/v1/person/add",
data: "name=John&location=Boston",
success: function(msg){
alert( "Data Saved: " + msg );
}
});
When I execute this to the server I get a request type of OPTION, which I think is the first call of the two needed to complete a POST request(?) Because these sites are not on the same domain (since calls are gonna be made remotely) it fails. The main problem however is that the request itself does not contain any data at all in the body. My guess is that this first call is not sending any data but waits for some sort of 'OK' to be able to send the data?? If not, why is it empty? I don't want to use the GET request since it says in the guidelines of a RESTful API that it should use POST for this purpose, plus I might want to send more data than GET can handle. So in case my assumptions are correct and this POST request fails because of cross-domain calls, what are my options?