I am trying to convert my ajax call using GET to one using POST. This is the one that works nicely with GET
. Changing the type to POST
does not work. Is the problem with the data string format?
$.ajax({
//type: "GET", //works
type: "POST", // Does Not Work
url: "/cgi-bin/my_perl.pl", // URL of the Perl script
contentType: "application/json; charset=utf-8",
dataType: "json",
//data format: "sid=" + sid + "&comments=" + comments,
data: data_string,
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert('AJAX Error');
}, // error
// script call was successful
// data contains the JSON values returned by the Perl script
success: function(data){
if(data.success) {
alert(data.success);
}
else if(data.error!=0) {
alert('We failed');
} //else
} // success
}); // ajax