jQuery刷新由php生成的div内容 [英] jquery to refresh div content generated by php

查看:73
本文介绍了jQuery刷新由php生成的div内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用jquery刷新同一PHP页面生成的div内容

How to refresh a div content generated by the same php page using jquery

我有一个test.php,其中包含一个名为refreshdiv的div,一个名为refreshbutton的按钮以及可能显示其他内容的其他div

i have a test.php, that contains a div called refreshdiv, a button called refreshbutton and may other div's that display other contents

refreshdiv div的内容是由php

the content of refreshdiv div is generated by php

是否可以在同一页面上单击refreshbutton时重新加载refreshdiv的内容,即test.php

is it possible to reload the contents of the refreshdiv on clicking refreshbutton on the same page ie, test.php

这是我的工作地点

<div id="refreshdiv">
<table>
 <?php 
   $rec=mysql_query("select * from user_master");
   for($i=0;$i<mysql_fetch_array($rec);$i++) 
   {
 ?>
 <tr>
   <td>
     <?php echo mysql_result($rec,$i,'username');?> 
   </td>
 </tr>
<?php } ?>
</table>
</div>

使用$ .get尝试,但没有得到任何结果

tried using $.get, but didnt get any result

推荐答案

看看这个 jsFiddle 我放在一起-可能会有帮助.

Take a look at this jsFiddle I put together - it may help.

我正在进行AJAX调用(在本例中为POST,因为它只是HTML,而jsFiddle支持HTML请求-但对于$.get来说并没有什么不同),它获取数据并将其附加到表数据单元格(<td>).整个页面不会更新-只是我要定位的部分-在这种情况下,是<td>单元格,该单元格始终附加"hello".

I'm making an AJAX call (a POST in this case since it's just HTML and that's what jsFiddle supports for HTML requests - but it would be no different for a $.get for you) that gets data and appends it to a table data cell (<td>). The whole page doesn't update - just the section that I'm targeting -- in this case, the <td> cell, which keeps having "hello's" appended into it.

我希望这会有所帮助.如果您还有其他问题,请告诉我.

I hope this helps. Let me know if you have add'l questions.

这篇关于jQuery刷新由php生成的div内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆