I'm trying to send an ajax call. I used a REST test extension for Chrome called Postman
[Link to it]. When I send the call with the extension it works, but when I send it via jQuery it doesn't work and I get as an error message: "error 0".
This is the request that the Postman tool sends to the server:
POST /form/front HTTP/1.1
Host: go.com
Cache-Control: no-cache
{ "sitename": "AAGx", "zone": 12, "sector": 34, "square": 7}
This is my code to send a request to the server:
function insert_newform() {
form_data = {sitename: 'AAGx', zone: 12, sector: 34, square: 7}
$.ajax({
type: "POST",
url: 'http://go.com/form/front',
data: JSON.stringify(form_data),
success: function(result) { alert("good!") },
error: function(jqXHR, textStatus, errorThrown) { alert(textStatus) }
});
}
$("#show").click(function() {
insert_newform()
}
);
I am unable to find out what's wrong with my call!
EDIT: go.com is just an example!
EDIT2: I'm going crazy.
Edit3: I updated my code to add JSON.stringify()
Edit4: when I put the files on the server and run the script it works great and everything is fine! But when I run the files locally on my machine, then the calls don't work and I get that error. I'm really going crazy! I can't figure out what's wrong :(
Edit5: maybe this has to do with this thing called CORS? But how does it come that it works from the Chrome Plugin but it doesn't work from my scripts locally?!!