从数据库使用php获取仪表板计数jquery ajax
问题描述:
我想使用PHP,jQuery和AJAX从数据库提取数据到HTML div
,但下面的代码不起作用。从数据库使用php获取仪表板计数jquery ajax
我刚开始学习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);
答
$(document).ready(function() {
$.ajax({
type:'POST',
url:'php_action/resourceqareportdashboardcount.php',
// dataType : 'json',
success:function(html){
$('#totalleadsmonth').html(html);
}
});
});
当你在'浏览器'中打开'console'窗口并检查网络部分/选项卡时,你是否从给定的ajax url获得了某个消息/结果? – eeya
*如何*它不起作用?描述你的问题!什么在工作?什么不是? 目前正在发生什么,目标是什么?您是否启用错误报告,并检查日志中是否有错误(PHP)和控制台(用于JavaScript错误)? – Qirel
@eeya是浏览器>控制台>未捕获SyntaxError:意外的输入结束 –