dqc22586 2011-08-28 19:48
浏览 71

如何将数据返回到jquery ajax回调函数?

How to return data to a jquery ajax callback function in which the data is coming from a PHP mysql query..

<script language="javascript" type="text/javascript">
   $(document).ready(function() {
        $.post("getMySqlData", function(data){

        });
   });
</script>

here's the PHP code which perform the mysql query to select data from a mysql database

  <?php
    $host = "127.0.0.1";
    $user = "root";
    $password = "problem2";
    $database = "scsi_test_log";
    $cxn = mysqli_connect($host, $user, $password, $database) or die ("couldnt connect to server");

    $query = "SELECT test_header FROM scsi_test";
    $result = mysqli_query($cxn, $query) or die ("Couldn't execute query.");
  ?>
  • 写回答

1条回答

  • dongzhi2014 2011-08-28 19:53
    关注

    Fetch the result into an array, and echo that in JSON encoding;

    $rows = array();
    while ( $row = mysqli_fetch_assoc( $result ) ) {
        $rows[] = $row;
    }
    
    echo json_encode( $rows );
    
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大