weixin_33705053 2018-06-21 17:38 采纳率: 0%
浏览 49

Ajax不显示PHP数据

I'm in a little trouble here. I'm trying to use ajax to get data from PHP server, that it gets from Mysql database; and then display into a specific html tag place. But, for some reason, nothing is showed off to html. I tested the PHP page and it works correctly. The point is, when ajax should get the data and display, it seems that there's nothing at database.

This is my html target :

<div class="container">

        <table>
                <thead>
                    <tr>
                        <th>Título</th>
                        <th>Curiosidade</th>

                    </tr>
                </thead>

                <tbody>

                </tbody>
            </table>
</div>  

This is my Ajax Script:

   function readData() {

          $.ajax({                                      
            type: "POST",
            dataType: "html",
            url: 'http://localhost/Gravidapp/php/read.php',                                           
            success: function(data){

              $('tbody').html(data);

            },
            error: function(xhr,desc,err){
                ajax.error(xhr);
                ajax.error(desc, err);
            } 
              });
          }; 

This is my PHP file:

   <?php

        require("bdconn.php");
        $pdo = new db();

        $pdo->mysql->beginTransaction();

        $rs = $pdo->mysql->query("select * from timeline");
        $rs->execute();

        while($row = $rs->fetch()){
        ?>
        <tr>
        <td><?php echo $row['titulocuriosidade']?></td>
        <td><?php echo $row['curiosidade']?></td>
        </tr>
        <?php
                  }

   ?>

Any suggests?

Thanks in advance

  • 写回答

2条回答 默认 最新

  • weixin_33727510 2018-06-21 18:14
    关注

    If the php response doesn't have the data type on headers ajax response could send an error.

    Try setting dataType="text html" on your ajax request this will try to convert the response from text to html

    also try to print errors on console to show whats is going wrong.

    error: function(xhr,desc,err){
        console.log(desc);
    }
    

    see dataType on: JQuery ajax

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog