Send XML in a js variable
I have this php code and the variable is XML data
$strXML = "<chart caption='ADI Chart Test ' xAxisName='Month' yAxisName='Units'"
$strXML.= "showValues='0'formatNumberScale='0' showBorder='1'>";
echo "<td align='right' onClick='drawchart($strXML)' > $totalcost </td> " ;`
this is passed to a javascript function
function drawchart(dataX) {
var chart1 = new FusionCharts("../charts/Pie3D.swf", "chart1Id", "400", "300","1");
chart1.setDataXML(dataX);
chart1.render("chart1div");
My problem is that the link is not dis开发者_如何学Cplayed correctly and more importantly there is no data when it gets to the js function
Could anyone tell me how to send xml data via a js variable please ?
You should encode the strXML in order to render it as valid HTML. Furthermore, you should enclose it with apostrophes so that it becomes a valid Javascript literal.
echo
"<td align='right' onClick='drawchart(\"" .
htmlspecialchars(json_encode($strXML)) .
"\")'> $totalcost </td>";
Seems you have missing something in this : echo "<td align='right' onClick='drawchart($strXML)' > $totalcost </td> " ;`
it should be:
echo "<td align='right' onClick='drawchart(\"$strXML\")' > $totalcost </td> " ;`
What is the end result you are looking for - ignoring the XML/JS portion?
If you are just trying to assign other attributes to the chart, couldn't you just load the data via the setDataURL
function:
var url="/path/to/data.php";
var chart1 = new FusionCharts("../charts/Pie3D.swf", "chart1Id", "400", "300","1");
url=escape(url);
chart1.setDataURL(url);
chart1.addParam("WMode", "Transparent");
chart1.render("chart1div");
精彩评论