I'm just taking my first steps with js/jquery, and I was trying to reload the content of a table using jquery but I'm not figuring out how:
if(isset($_POST['mode']) && $_POST['mode'] == "toggleactive"){
$admin = new funcadmin($dbo);
if($admin->toggleState($_POST['id_users'])){
$table = $admin->getUsers();
echo json_encode($table); //??????
}
else{
$erroruser = 'Erro!';
echo json_encode($erroruser);
}
}
and on the view:
<table id="userlist">
<?php echo $table; ?> //How I load the original table
</table>
<script>
function toggleState(id_users){
$.ajax({
type: "POST",
url: "admin.php",
data: {id_users:id_users, mode:"toggleactive"},
dataType: "JSON",
success: function(table) {
$("#userlist").innerhtml('table');
},
error: function(err) {
alert(err);
}
});
}</script>
Many thanks in advance, Cheers, Baya
The problem had nothing to do with JQuery properly. The problem was here: if($admin->toggleState($_POST['id_users']))
I never told the function to return true, was kind of expecting that the return of the ->execute() to be enough. Now that I did its all working well.
My sincere applologies for your lost time, and thank you all for all the help you were willing to give.
Cheers, Baya
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.