I am using the jQuery post method from : http://www.w3schools.com/jquery/jquery_ajax_get_post.asp
$("button").click(function(){
$.post("demo_test_post.pl",
{
name: "Donald Duck",
city: "Duckburg"
},
function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});
});
The server side script is in perl. The print statements in perl are getting in the data parameter of the callback function. And I am always getting status as "success"
Basically I need to propagate an error condition to the front-end which I am not able to simulate. I have tried die, exit and return with different values but in all cases I get status as "success".
How can I get the non-success status for this jQuery function?
Also Is there a cleaner way to receive the error condition from the back-end perl server?
Below is the perl code on the server side:
#!/usr/bin/env perl
#|++
use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $q = new CGI;
main();
sub main()
{
if($q->param())
{
my $name = $q->param('name');
my $city = $q->param('city');
print('You entered'.$name.' and '.$city);
}
}
With above code I have experimented with return, die & exit but I always get success as status.