jquery

jQuery binding to a form submit


I'm doing the following:

    // Post to the server
    $.ajax({
        type: 'POST',
        url: $("form.edit_item").attr("action"),
        data: $("form.edit_item").serialize(),
        success: function(e) {
        }
    });


$(".edit_item")
    .bind('ajax:loading', function() {
        alert('go');
    })
    .bind('ajax:success', function(data, status, xhr) {
        alert('going');
    })
});

On the form:

<form accept-charset="UTF-8" action="/xxxxx/18" class="edit_item" id="edit_item_31" method="post"><div 

While the form posting works fine.the ajax binds are not working. What can I try next?


Solution

  • In your $.ajax options, add a beforeSend handler:

      $.ajax({
        type: 'POST',
        url: $("form.edit_item").attr("action"),
        data: $("form.edit_item").serialize(),
        beforeSend: function() {
            alert('go');
        },
        success: function(e) {
            alert('going');
        }
    });