javascript - parse html and invoke submit button using jquery -


i calling web service method , trying invoke action. however, theresponse 'html'. need parse , invoke submit button , append output.

here's how html (data) looks like:

 <form target="_blank" action='../someservice.asmx/action' method="post">   <table >           <tr>         <td></td>         <td align="right"><input type="submit" value="invoke" class="button"></td>     </tr>   </table> </form> 

here's jquery part:

$(data).find('form').find('input[type="submit"]').submit(function(e){     $('#result').append(output);     event.preventdefault();                 });   

i see 3 issues, first, prevent default should first line of handler (my guess), second, calling event.preventdefault handler has parameter named e, , third, should call submit event on form, not on input:

data = $.parsehtml(data); $(data).find('form').submit(function(event){     event.preventdefault();       $('#result').append(output); }); 

i'm not sure if preventdefault call should @ beginning of handler, opinion it's easier know that handler preventing default behavior of event.

edit

after comments, here believe want do:

data = $.parsehtml(data); var $form = $(data).find('form'); $form.submit(function(event){     event.preventdefault();     $.ajax({         type: 'post',         url: $(this).attr('action'),         data: $(this).serialize(),         success: function (data) {             $('#result').append(data);         },         error: function (error) {             console.log(error);         }     }); }); $form.trigger('submit'); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -