简体   繁体   English

如何通过php变量将html传递给jquery

[英]How to pass html through a php variable into jquery

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: 我只是迈出了使用js / jquery的第一步,我试图使用jquery重新加载表的内容,但我不知道如何:

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. 该问题与JQuery无关。 The problem was here: if($admin->toggleState($_POST['id_users'])) 问题出在这里: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. 我从没告诉过函数返回true,只是希望-> execute()的返回就足够了。 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 干杯,巴亚

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM