POST request reaches server but empty
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 开发者_如何学Gocontain 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?
Edit: Now I see that you're trying to do cross-domain Ajax queries... that's a non-starter. See here for additional info (just searched cross domain and picked one): AJAX cross domain call
精彩评论