doy57007 2012-10-11 04:23
浏览 55
已采纳

Jquery - 从数据库中获取注释

oI am having problem fetching comments from MySQL database using jQuery.

I am trying this way, but its not working.

PHP (comments.php)

<?php 

    if (isset($_POST['value1'])) {
        $id = ($_POST['value1']);
    }else{
        $id = '';
    } 
    if (isset($_POST['value2'])) {
        $database = ($_POST['value2']);
    }else{
        $database = '';
    } 
    if (isset($_POST['value3'])) {
        $tablename = ($_POST['value3']);
    }else{
        $tablename='';
    } 

    require_once('rt-connect.php');

    $find_data = "SELECT * FROM $tablename";
    $query = mysqli_query($connection, $find_data);
?> 



  <?php while($row = mysqli_fetch_assoc($query)):?>
  <div class="comment-container">
    <div class="user-info"><?php echo $row['user_name']; ?></div>
    <div class="comment"><p><?php echo $row['comment']; ?></p></div>
  </div>
  <?php endwhile;?>

Jquery(comments.html)

     var id=2;
 var database='comments_db';
 var tablename='comments';

 $.post('comments.php', {value1:id, value2:database, value3:tablename}, function(data)
    {
    $('#comments').load('comments.php .comment-container');
 });

Html(div on comments to load on comments.html)

      <div id="comments"></div><!--end of comments-->

Please see and suggest any possible way to do it.

Thanks

  • 写回答

4条回答 默认 最新

  • dreamy6301 2012-10-11 04:29
    关注

    You have $.load() inside success function of $.post(), try this..

    $.post('comments.php', {value1:id, value2:database, value3:tablename}, function(data)
       {
       $('#comments').html(data);
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 为啥画版图在Run DRC会出现Connect Error?可我Calibre的hostname和计算机的hostname已经设置成一样的了。
  • ¥20 网站后台使用极速模式非常的卡
  • ¥20 Keil uVision5创建project没反应
  • ¥15 mmseqs内存报错
  • ¥15 vika文档如何与obsidian同步
  • ¥15 华为手机相册里面的照片能够替换成自己想要的照片吗?
  • ¥15 陆空双模式无人机飞控设置
  • ¥15 sentaurus lithography
  • ¥100 求抖音ck号 或者提ck教程
  • ¥15 关于#linux#的问题:子进程1等待子进程A、B退出后退出(语言-c语言)