目前,我正在尝试使用google的可视化工具绘制一些动态加载的图表。
我想从sql数据库中提取数据。我有一个能够这样做的php脚本(getnumber.php)。
我试图在我绘制图表的javascript中使用这个php脚本。
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function drawChart(Z)
{
tmpdata = new google.visualization.DataTable();
datalist.push(tmpdata);
datalist[Z].addColumn('string', 'Complete');
datalist[Z].addRows([['Finished', $.ajax({url:"getnumber.php"})], ['Incomplete', 10]]);
.
.
.
}
window.setInterval("drawChart()", 1000);
</script>我意识到对$.ajax的这种使用是完全错误的,但我很困惑!
发布于 2012-08-01 17:09:18
您应该尝试使用$.post()或$.get()函数,而不是使用基本的ajax函数。无论如何,您可以以这种方式操作thsoe 3函数中的数据。
$.post('getnumber.php',function(data){
/* Do whatever you want with the data you grabbed from the php page. */
});我不知道你的问题到底是什么,但我希望这能帮到你。
祝您今天愉快!
编辑:函数本身不包含数据,它包含在$.ajax()调用的$.ajax()部分中。
Edit2:与其他两个函数相比,$.ajax();函数有一个名为success(data, textStatus, jqXHR)的参数,可以使用该参数。
http://api.jquery.com/jQuery.ajax/
发布于 2012-08-02 09:58:54
最后,我使用了以下内容:
my_url="dosomething.php";
function getvar() {
var json = null;
$.ajax({
'async': false,
'global': false,
'url': my_url,
'dataType': "json",
'success': function (data) {
json = data;
}
});
json = parseInt(json);
return json;
};php脚本的结尾为:
echo json_encode($id_max);
由于某些原因,我无法让$.post工作。不管怎样,谢谢你的帮助。
https://stackoverflow.com/questions/11764080
复制相似问题