duanoucuo7045 2015-02-18 16:40
浏览 12

PHP返回没有找到数据

Php is returning "no data found" on ajax request. Here is my php code and the ajax call. In the network section php is request is not showing up. But in the console a error saying that no data found is appearing. Please help out with this.

    <?php
    include 'dblinker.php';
    function getDetails(){
try {
        $link = linkToPoints();
        $handle = $link->prepare("SELECT * FROM leafly WHERE id < 11");
        $handle->execute();
        if(!($handle->rowCount())) {
                return "No data exists";
        }
        $result=$handle->fetchAll(\PDO::FETCH_OBJ);
        return json_encode($result);
    }
catch(Exception $e){
        return "Connection Error";
    }
}
echo getDetails();
?>

This is my JS file.

var timer;
$(document).ready(function(){
        fetchdata = function(){
                $.ajax({
                url: 'services/get_data.php',
                type: 'GET',
                success: function(json) {
                console.log(json)
                var json1 = jQuery.parseJSON(json);
                for(i=0; i < json1.length; i++)
                {
                    tr = $('<tr/>');
                    tr.append("<td>" + json1[i].id + "</td>");
                    tr.append("<td>" + json1[i].mod_name + "</td>");
                    tr.append("<td>" + json1[i].product_type_id + "</td>");
                    onemore=tr
                    $('#device_1').append(tr.clone());
                    $('#device_2').append(onemore.clone());
                }
                }
                });
        }
        fetchdata();
        $("#start").click(function() {
                timer = setInterval(function(){
                                $("#device_1,#device_2").find('tr').remove();
                                fetchdata();
                        },1000);
        });
        $("#stop").click(function() {
                clearInterval(timer);
        });
});
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
    • ¥15 这种微信登录授权 谁可以做啊
    • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
    • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
    • ¥15 网络设备配置与管理这个该怎么弄
    • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!