我如何从带有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>
答案 0 :(得分: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 );
答案 1 :(得分:0)
使用jQuery的.load()
方法:
$("#divid").load("/path/to/script.php");