0

我如何使用 ajax 从 php 文件中获取这一行来替换 div 的当前 html

<div style = "width:260px;height:400px;max-height:400px;overflow:auto;">
  <textarea name = "message" onkeydown="send(event, '<?php echo $trow['id'];?>');" id = "text<?php echo $trow['id'];?>" style = "max-height:60px;width:240px;height:20px;overflow:hidden;resize:none;"></textarea>
  <table class = "table">
    <?php 
       while($erow = mysql_fetch_array($erun)){
       $fromid = $erow['fromid'];
       $us = mysql_query("select * from user where id = $fromid");
       $fus = mysql_fetch_array($us);
       ?>
    <tr><td>
        <div id = "change<?php echo $trow['0'];?>">
          <a class="pull-left" href="#">
            <img src = "profpic/<?php echo $fus['14'];?>" class="media-object" style = "margin-right:5px" height = "40px" width = "40px">
          </a>
          <div class="media-body">
            <h6 class="media-heading"><b><?php echo $fus['title']?> <?php echo $fus['fname']?> <?php echo $fus['lname']?></b></h6>
            <font size = "2"> <?php echo $erow['content']?>
          </div>
    </td></tr>
    <?php } ?>
  </table>
  </div>
</div>
4

2 回答 2

0

使用 jQuery 的.load()方法:

$("#divid").load("/path/to/script.php");
于 2013-10-07T19:11:58.050 回答
0

如果我明白了您的问题,您需要输出 JSON 数据,对吗?然后你必须使用 PHP 提供的json_encode()方法,像这样:

原型:

string json_encode ( mixed $value [, int $options = 0 [, int $depth = 512 ]] );

您应该拥有的代码:

$information = " <div style ='width:260px;height:400px;max-height:400px;overflow:auto;'>
    <textarea name = 'message' onkeydown='send(event,'<?php echo $trow['id'];?>');' id ='text<?php echo $trow['id'];?>' style = 'max-height:60px;width:240px;height:20px;overflow:hidden;resize:none;'></textarea>
    <table class = 'table'>
    <?php 
    while($erow = mysql_fetch_array($erun)){
    $fromid = $erow['fromid'];
    $us = mysql_query('select * from user where id = $fromid');
    $fus = mysql_fetch_array($us);
    ?>
    <tr><td>
    <div id = 'change<?php echo $trow['0'];?>'>
    <a class='pull-left' href='#'>
    <img src = 'profpic/<?php echo $fus['14'];?>' class='media-object' style = 'margin-right:5px' height = '40px' width = '40px'>
    </a>
    <div class='media-body'>
    <h6 class='media-heading'><b><?php echo $fus['title']?> <?php echo $fus['fname']?> <?php echo $fus['lname']?></b></h6>
    <font size = '2'> <?php echo $erow['content']?>
    </div>
    </td></tr>
    <?php } ?>
    </table>
    </div>
    </div> ";

echo json_encode( $information );
于 2013-10-07T18:47:25.887 回答