我想要在這裏工作的圖表是代碼。通過頁面的div標籤中的ajax請求加載圖形
graph.php
<?php $mak="1";
$sen="5";
?>
<html>
<head>
<title>Pollution Mapper</title>
<!-- Load jQuery -->
<script language="javascript" type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js">
</script>
<!-- Load Google JSAPI -->
<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 jsonData = $.ajax({
type: "POST",
url:"json.php" ,
dataType: "json",
data: { mak: <?php echo $mak; ?> , sen: <?php echo $sen; ?> },
async: false,
success: function(){
alert("asd");
}
}).responseText;
var data = new google.visualization.DataTable($.parseJSON(jsonData));
var chart = new google.visualization.AreaChart(
document.getElementById('Chart_div'));
chart.draw(data);
}
</script>
</head>
<body>
<div id="Chart_div"></div>
</html>
AJAX請求調用上述網頁是
$(document).on('click', '.jqf', function() {
$.ajax({
type: "POST",
url: "./graph.php",
data: { mak: $('.makid').attr('id') , sen: $(this).attr('name') },
success: function(){
}
});
return false;
});
上面的函數是index.html文件內。我想在沒有重新加載文件的情況下在index.html文件中加載圖形。我應該怎麼做?
你在PHP中有一個Javascript函數? – Shahar
是的JavaScript函數是在PHP文件中。 – user2147744
你想從./graph.php獲得成功嗎? – Popo