我在include中有以下功能:
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Customers', 'Status'],
['Accepted', <?php echo $rowsaccepted ;?>],
['Declined', <?php echo $rowsdeclined;?>],
['Not Reviewed', <?php echo $rowsnreview;?>]
]);
var options = {
'width':200,
'height':200,
'backgroundColor':'#474747',
'legend': 'none',
'chartArea':{left:20,top:0,width:250,height:250},
colors: ['#ef8200', '#007fc2', '#41cf0f'],
fontSize:14,
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
</script>
正如您所看到的,它接受三个PHP变量,这些变量由查询定义到另一个包含的MySQL表中。该函数根据需要工作,图表表示数据,但仅在页面加载或重新加载时(如预期的那样)。
我有以下AJAX触发更新变量的查询:
<script type="text/javascript">
$(function() {
$(".accept").click(function(){
var element = $(this);
var del_id = element.attr("id");
var order_id = element.attr("data-order");
$.ajax({
type: "POST",
url: "accept.php",
data: {id:del_id,order_id:order_id},
success: function(){}
});
$(this).parents("#show").animate({ backgroundColor: "#003" }, "slow")
.animate({ opacity: 0.25 }, "slow");
});
});
</script>
我喜欢在AJAX调用成功时执行该函数。我是否只需将其添加到成功部分,如下所示:
$.ajax({
type: "POST",
url: "accept.php",
data: {id:del_id,order_id:order_id},
success: function drawChart
});
我必须有一些错误,因为当函数添加到成功时,AJAX调用不再起作用。这是最好的方法还是在AJAX结尾处的简单location.reload会出现问题?
由于