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 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号