1

I am trying to send to php the result of an ajax form, however which button was pressed (submit or cancel) is important to the php code, but is lost during the ajax. I am trying to uncover which button was pressed to submit the form, but my code is not working.

Can someone point out what is going wrong here?

$('.form').live('submit', function(event) {

    var messageTo = $(this).next();
    var button = event.target;
    var data = $(this).serialize();

    data = data + "&" + button.name + "=" + button.value;

    $.post(
        'a.php',
        data,
        function(data){
                messageTo.html(data.message);               
        }, "json"
    );

    return false;

});
4

1 回答 1

0

此行应该为您提供触发事件的元素

var button = event.target.nodeName;
于 2012-08-01T02:45:14.770 回答