【问题标题】:fetch dashboard count from database using php jquery ajax使用 php jquery ajax 从数据库中获取仪表板计数
【发布时间】:2017-10-24 22:20:21
【问题描述】:

我正在尝试使用 PHP、jQuery 和 AJAX 从数据库获取数据计数到 HTML div,但下面的代码不起作用。

我刚开始学习ajax,请帮忙。谢谢!

index.php

            <div class='col-lg-3 col-md-6'>
                <div class='panel panel-primary'>
                    <div class='panel-heading'>
                        <div class='row'>
                            <div class='col-xs-3'>
                                <i class='fa fa-microphone fa-5x'></i>
                            </div>
                            <div class='col-xs-9 text-right'>
                                            <!-- here i want to fetch result -->
                                            <div id="leadmonth"></div>
                                <div>Total Leads</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

jQuery

$(document).ready(function() {

        $.ajax({
            type:'POST',
            url:'php_action/resourceqareportdashboardcount.php',
            dataType : 'json',
            success:function(html){
                $('#leadmonth').html(html);
            }

});

PHP

<?php
// This Month Count
require_once 'db_config.php';
$output= '';
$sql = "SELECT * FROM leads WHERE YEAR(leadcreationdate) = YEAR(NOW()) AND MONTH(leadcreationdate)=MONTH(NOW())";
$query = $connect->query($sql);
$totalleads = mysqli_num_rows($query);

        if ($monthtotalleadscount > "0") {
            $output = "<div class='huge'>$totalleads</div>";
        } else {
            $output =  "<div class='huge'>0</div>";
        }

// database connection close
$connect->close();

echo json_encode($output);

【问题讨论】:

  • 当您在您使用的“浏览器”中打开 console 窗口并检查 Network 部分/选项卡时,您是否从给定的 ajax 中收到特定消息/结果网址?
  • 如何它不起作用?描述你的问题!什么在起作用?什么不是?目前正在发生什么,目标是什么?您是否启用了错误报告,并检查您的日志是否有错误 (PHP) 和控制台(是否有 JavaScript 错误)?
  • @eeya 是的,浏览器中有一个错误 > 控制台 > 未捕获的 SyntaxError: Unexpected end of input
  • 完成...在 jquery 中做了一些小改动并解决了问题...现在更新答案...谢谢@eeya 我不知道我们可以在浏览器控制台中检查错误...我是不仅仅是从互联网上学习所有这些的开发人员。

标签: php jquery mysql ajax dashboard


【解决方案1】:
$(document).ready(function() {

        $.ajax({
            type:'POST',
            url:'php_action/resourceqareportdashboardcount.php',
            // dataType : 'json',
            success:function(html){
                $('#totalleadsmonth').html(html);
            }
            });

});

【讨论】:

    猜你喜欢
    • 2014-05-03
    • 2021-04-01
    • 2017-03-04
    • 1970-01-01
    • 2019-11-26
    • 2014-10-17
    • 2017-04-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多