FusionCharts PHP with Ajax -
i'm using fusioncharts free populate chart.
in main.php:
<html> <head> <script language="javascript" src="fusioncharts/fusioncharts.js" ></script> <script language="javascript"> function ajax(divid) { if (window.xmlhttprequest) xmlhttp=new xmlhttprequest(); else xmlhttp=new activexobject("microsoft.xmlhttp"); xmlhttp.onreadystatechange=function() { if (xmlhttp.readystate==4 && xmlhttp.status==200) document.getelementbyid(divid).innerhtml=xmlhttp.responsetext; } return xmlhttp; } function detailedchart(couid) { xmlhttp = ajax("detaileddiv"); xmlhttp.open("get", "getdetailedresult.php?couid=" + couid, true); xmlhttp.send(null); } </script> </head> <body> <?php $strdataurl = "getresult.php"; echo renderchart("fusioncharts/fcf_column3d.swf", $strdataurl, "", "chart1", 600, 300); ?> <div id="detaileddiv" align="center"></div> </body> </html>
in getresult.php:
if ($result) $chart -> adddatafromdatabase($result, "total", "name", "", "javascript:detailedchart('##id##')");
in getdetailedresult.php
<?php $chart -> newfusioncharts("column3d", "900", "500"); $chart -> setswfpath("fusioncharts/"); $chart -> setchartparams("caption=...."); $chart -> adddatafromdatabase($result, "total", "name"); $chart -> renderchart(); ?>
the problem create drilldown getresult getdetailedresult using ajax, show me "chart." instead of chart. if change
$chart -> renderchart(); $chart -> renderchart(true);
it show me bgcolor="".
why happening , how can solve it? there other simpler way populate detailedchart through ajax?
million thanks.
if investigate, see getting html
(a div
) , script
(some javascript code render chart in div
) in responsetext
.
now, when set responsetext
innerhtml
of html element, html dom parser adds , displays html part (div text chart
). however, not execute script
part (that intended render chart inside div
replacing chart
text.
the ideal way achieve rendering execute script
.
this managed if use jquery
ajax function, similar to:
function detailedchart(couid) { jquery.ajax({ url: "getdetailedresult.php?couid=" + couid, success: function(responsetext) { jquery("#detaileddiv").html(responsetext); } }); }
note: need load jquery js file in head of html.
Comments
Post a Comment