After ajax call, my form doesn't work.
I have a table of servers like this :
||server_name || server_port || report_date || isMonitored || Status || delete.jpg update.jpg ||
Created by this code in : table.php
$edit ="<input id=\"updating\" title=\"Change Monitoring Status\" type=\"image\" name=\"action\" value=\"Update\" src=\"add/img/edit.png\" alt=\"edit\" height=\"12\" width=\"12\">";
$delete ="<input id=\"deleting\" title=\"Delete this server\" type=\"image\" name=\"action\" value=\"Delete\" src=\"add/img/delete.png\" alt=\"edit\" height=\"12\" width=\"12\">";
$table .= "
<form id=\"serverform\" action=\"action.php\" method=\"POST\"><tr class=".$tr_class.">
<td><input type=\"hidden\" name=\"server_name\" value=\"".$row['server_name']."\"><a target=\"blank\" href=\"http://".$row['server_name'].":".$row['server_port']."\">".$row['server_name']."</a></td>
<td><input type=\"hidden\" name=\"server_port\" value=\"".$row['server_port']."\">".$row['server_port']."</td>
<td>".$row['report_date']."</td>
<td>".$row['monitored']."</td>
<td>".$status."</td>
<td>".$edit." ".$delete."</td>
</tr></form>";
echo $table;
In my index.php, I call table.php like this :
<tbody id="table"></tbody>
<script>
(function worker() {
$.ajax({
url: 'table.php',
success: function(data) {
$('#table').html(data);
},
complete: function() {
// Schedule the next request when the current one's complete
setTimeout(worker, 30000);
}
});
})();
</script>
The table refresh every 30s. If I used the url server/table.php, the form is working, but not if i go on server/index.php, the form is only displayed.
I'm new in ajax, I did some research and it seems that's what I'm doing wrong, can you help me to fix my problem ?