Im having an issue with jQuery losing its binding to a class after an ajax update. Ive done this before, and CANT NOT find where my issue is, so im asking for help.
I have a form:
<div id="confirmed_tile">
<form id="form_id" name="form_name" class='whatsdone'>
</table>
<tr>
<td>
Name
</td>
<td>
Name
</td>
<td>
Name
</td>
</tr>
</table>
<input type="submit" id="press_submit">
</form>
</div>
Then I have some jquery that handles the form submittion:
$(document).on('submit','.whatsdone',function(){
var url = "ajax/update_appointment_clinic.php";
$.ajax({
type: "POST",
url: url,
data: $( this ).serialize(),
success: function(data)
{
$( "div#confirmed_tile" ).html(data);
}
});
return false;
});
This ajax call both submits the form for updating mysql, and echo's back the form with the updated info and sends back to the page with the form on it.
This is all working great, but once I submit and ajax updates the div, the ajax call no longer works. I know this is because of an issue with the form class losing it binding to the jquery function, but I thought my choice of $(document).on('submit','.whatsdone',function() would solve this issue. It does not. Can anyone tell me where I went wrong?
Responce data back from ajax:
<table width='100%' border='0' id='large' cellspacing='0' class='tablesorter table'>
<thead>
<tr>
<th rowspan='3'><p>Time</p></th>
<th rowspan='1'><p>First</p></th>
<th rowspan='1'><p>Last</p></th>
<th rowspan='2'><p>Pet Name</p></th>
<th rowspan='4'><p>APT</p></th>
<th rowspan='4'><p>Species</p></th>
<th rowspan='4'><p>Phone #</p></th>
<th rowspan='4'><p>Status</p></th>
<th rowspan='4'> </th>
<th rowspan='4'> </th>
<th rowspan='4'> </th>
</tr>
</thead>
<tbody>
<tr>
<td><p>2:00 pm</p></td>
<td><p>B</p></td>
<td><p>Bozley</p></td>
<td><p>Holly</p></td>
<td><p>(233)</p></td>
<td><p>Canine</p></td>
<td><p>555-555-5555</p></td>
<form name='6' method='post' class='whatsdone'>
<input type='hidden' name='app_id' value='6'>
<input type='hidden' name='clinic_id' value='20'>
<input type='hidden' name='appointment_date' value='2015-02-05'>
<input type='hidden' name='first_visit_apt' value='233'>
<td style='max-width:100px'><p>
<select name='confirm_value'>
<option value='1'><p>Confirmed</p></option>
<option value=5>Left Voicemail</option>
<option value=4>Left Message w/ Person</option>
<option value=3>Rescheduled</option>
<option value=1>Confirmed</option>
<option value=0>Unconfirmed</option>
<option value=2>Cancelled</option>
<option value=6>Could Not Reach</option>
</select></p>
</td>
<td style='max-width:30px'>
<input type='submit' data-form='6' class='update_confirmed_button' value='GO'>
</td>
</form>
<td style='max-width:30px'><p>11:11 pm</p></td>
<td style='max-width:30px'>
<div class='color_5' title='Participant with responce'>
<div style='display:none'>5</div>
</div>
</td>
</tr>
</tbody>
</table>
Thank you Jason
$( "div#confirmed_tile" )doesn't maych anything in the html you provide (did you meancancelled_tile?)confirmed_tileand the div you have in htmlcancelled_tiledid not match. So is that a mistake or you have some oter div with that iddatain Ajax call has the same classwhatsdone?console.log('test')at the start of the function, so not in the AJAX request but before it and checking whether it is called at all. Also you could try using$('body').on()instead of$(document).on(), although this is just a hunch.