Search code examples
jqueryajaxformon-the-fly

Making an on-the-fly 'ajaxForm'


I am trying to use ajaxForm on my on-the-fly created form. In fact, my application will produce a link 'on the fly' and by clicking on that link, it will produce an ajaxForm (again on-the-fly by jQuery!), so I used the .live() function with ajaxForm(). This is my wrong code:

$('form').live('submit', function() {
    $(this).ajaxForm({dataType: 'html', success: function(data) {
        alert(data);
    }});
    return false; // For preventing page refresh!
});

In my form, when I click the submit button, the page refreshes.

Is there a solution?


Solution

  • As others have said, your return false should work.

    So, something else is wrong. Ensure that jQuery is loaded properly and that your on-submit handler actually executes by placing debugging code in it.

    Also, make sure that you have Firebug installed and enabled (or equivalent for your browser) so that you can perform your debugging.