Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery $.post success function never fires

I have a $.post which using Fiddler I can see always posts successfully but my success function is never fired.

A successful post to the url returns a 1 or failure returns a 0, on each occasion I have tested it returns the expected value of 1 so I'm at a lost as to what I'm doing wrong?

if ($('#mycheckbox').prop('checked')) {
    $.post('/base/MailingList/Subscribe/',
        {
            listId: $('#mycheckbox').val(),
            name: $('#subscriber-name').val(),
            email: $("#subscriber-email").val()
        },
        function(response) {
            console.log(response);
        });
}
like image 386
ProNotion Avatar asked Oct 11 '13 16:10

ProNotion


1 Answers

Stick another function as a final callback. That function will run in the failure case.

The way jquery recommends doing it is this:

var jqxhr = $.post( "example.php", function() {
   alert( "success" );
})
.done(function() {
    alert( "second success" );
})
.fail(function() {
    alert( "error" );
})
.always(function() {
    alert( "finished" );
 });
like image 154
Zeke Nierenberg Avatar answered Nov 01 '22 15:11

Zeke Nierenberg