javascript - Form doesn't serialize after Ajax insertion -


tearing hair out on this. have 40 rows of simple forms being generated dynamically mysql database. each form has unique id based on database id. after clicking submit results updated in database , inserted div (#result).

works first time perfectly. after first time script won't serialize updated form data. id fine (checked via alert) formdata empty (also checked via alert).

thinking need re-target form somehow? appreciated. thanks.

$('#result').on('click', '.submitform', function () {     var id = $(this).attr('id');     var formdata = $('#'+id+'-form').serialize();     $.ajax({         type: "post",         url: "ajax-process-form.php",         data: formdata,         cache: false,         success: function(server_response){             $("#result").html(server_response).show();         }     });     return false; }); 

just reasoning... might wrong...

this code

$('#result').on('click', '.submitform' 

binds click event on result , filters .submitform, executes this being .submitform

when success comes server, rewriting #result

$("#result").html(server_response) 

if server_response not contain .submitform next calls first onclick event not execute because .submitform not exist anymore inside #result

if error, solve, use div show result instead of #result or bind click separated, not contained within div


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 -