开发者

jquery: how use sumbit() functions in click() event?

How use submit and ajax functions on click event? I need send input hidden to server using a link but no found in click event.... any solution? please help!

p.d. sorry for my english xd

     $('#delete_link').click(function() {


                           $('#myform').submit(func开发者_StackOverflow中文版tion() {

                                if ($('#codigo').val().length < 1) {$('#notice').html('Error'); return false; }

                                $.ajax({   
                                      type: "POST",   
                                      url: 'mantenimiento.php?action=Eliminar',  

                                      data: $(this).serialize(),   
                                      success: function(data) {

                                            switch(data){
                                                case 'success':
                                                    window.location.reload();
                                                    break;
                                                default:
                                                    $('#notice').html('<p class="error">'+data+'<\/p>');
                                                    break;
                                            }
                                      }   
                                });
                                return false;
                            });

            });


this bit:

$('#delete_link').click(function() {
    $('#myform').submit(function() {

is only binding the function to the submit event on #myform (when #delete_link is clicked), but doesn't actually trigger the event.

I think what you want is something like:

$('#myform').submit(function() {
  // stuff to do when submit
});
$('#delete_link').click(function() {
    $('#myform').trigger('submit');
});


You're adding a handler to the submit event which makes your AJAX request.

You need to make the AJAX request directly, without involving the submit evemt.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜