WeaponX86
WeaponX86

Reputation: 197

Attaching ajax function to form submit fails

I'm trying to write a simple plugin to attach to form submit , like a simpler version of this: http://jquery.malsup.com/

Here is my code: http://jsfiddle.net/RYh33/6/

The go() function is defined outside document ready and then immediately called on document ready. This call works and returns status 200.

As soon as you click one of the Submit buttons, Firebug shows the POST is aborted. What is going on?

Upvotes: 0

Views: 38

Answers (1)

Skyline969
Skyline969

Reputation: 431

I believe that you need to have a return value if you're going to be writing something custom for your form submit. For example, take a look at something I wrote a few days ago:

$('#cmdform').submit(function(e){
    if ($('#param').attr('disabled') != 'disabled' && $.trim($('#param').val()) == ''){
        // This interrupts the form submit
        e.preventDefault();
        alert('Enter the required parameter first');
        $('#param').val('');
        return false;
    } else if ($('#router option:selected').val() == 'none'){
        e.preventDefault();
        alert('Choose a proper device');
        $('#param').val('');
        return false;
    } else {
        $('#output').empty();
        $('#output').append('<p>Loading, please wait....</p>');
        $('#execute').attr('disabled', 'disabled');
        return true;
    }
});

As you can see here, every path of my submit function returns true or false. Try that and see where it gets you.

Upvotes: 1

Related Questions