Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用json编码和ajax返回html中的数据_Php_Json_Ajax - Fatal编程技术网

Php 如何使用json编码和ajax返回html中的数据

Php 如何使用json编码和ajax返回html中的数据,php,json,ajax,Php,Json,Ajax,我试图使用JSON和ajax显示数据库中的数据,但我很难做到这一点。请帮忙,谢谢 //我的js函数 function show_messages(){ $.ajax({ url: "display_table.php", cache: false, success: function(html){ $("#table_content").html(html); } }); }

我试图使用JSON和ajax显示数据库中的数据,但我很难做到这一点。请帮忙,谢谢

//我的js函数

function show_messages(){
     $.ajax({
         url: "display_table.php",
         cache: false,
         success: function(html){
             $("#table_content").html(html);
         }
     });
 }


 <?php    

您有什么问题?如果在浏览器中加载
display_table.php
时,您得到一个表,那么ajax调用应该显示它。我想使用json encode函数创建一个数组,并通过ajax返回要显示的数据,例如,您有什么问题?如果,当您在浏览器中加载
display_table.php
时,您会得到一个表,然后ajax调用会显示它
if(isset($_REQUEST['AnswerId'])){ $AnswerId = $_REQUEST['AnswerId']; }
else {$AnswerId = 0; }

$i=0;
while ($mytablerow = mysql_fetch_row($result)){
$mytable[$i] = $mytablerow; 
$i++;   
}

function tree($treeArray, $level, $pid = 0) {
global $AnswerId;
if (! $treeArray) 
{ return; } 
     foreach($treeArray as $item){
    if ($item[1] == $pid){
        ?>  
        <div class="CommentWithReplyDiv" style="margin-left:<?php echo($level*60);?>px">    
        <div class="CommentDiv">
        <div class="User"><?php echo($item[2]) ; ?></div>
        <div class="Message"><?php echo($item[3]) ; ?></div>
        <div class="Date"><?php echo($item[4]) ; ?></div>
        <?php               
if ($level<=10) 
{ echo '<a href="" class="ReplyLink" onclick="AnswerComment('.$item[0].');return false;">Reply</a>'; }
echo '<a href="" class="DeleteLink" onclick="DeleteComment('.$item[0].');return false;">Delete</a>';
        ?> </div> <?php

        if ($AnswerId == $item[0]){
            ?><div id="InnerDiv"><?php
            ShowForm($AnswerId);
            ?></div><?php   
        } 

        ?> </div> <?php 
        echo ('<br/>');
        tree($treeArray, $level+1, $item[0]);
    }       
} }
tree($mytable, 0);
?>