Gax*_*xZE 1 javascript php mysql variables function
我有这个代码
var myChart = new FusionCharts("../themes/clean/charts/hbullet.swf", "myChartId", "400", "75", "0", "0");
myChart.setDataXML("<chart lowerLimit='0' upperLimit='100' caption='Revenue' subcaption='US $ (1,000s)' numberPrefix='$' numberSuffix='K' showValue='1'><colorRange><color minValue='0' maxValue='50' color='A6A6A6'/><color minValue='50' maxValue='75' color='CCCCCC'/><color minValue='75' maxValue='100' color='E1E1E1'/></colorRange><value>78.9</value><target>80</target></chart>");
myChart.render("chartdiv");
Run Code Online (Sandbox Code Playgroud)
现在我想编辑此代码中的一些值.
然而,为了使事情变得更复杂我使用PHP函数来编写"chartdiv"div,我需要将数据库值放入此代码中.是否有可能将PHP变量从我的PHP函数滑入此.js文件?或者用PHP编写javascript更好甚至可能?
<script src='thejs.php'>
并让脚本输出javascript.就个人而言,我喜欢将变量放在一个结构(比如一个数组)中,然后将其转换为JSON.这样,您可以轻松添加和删除变量,并检查它们在JS中的存在.JSON是让两种语言进行通信的简单方法.