我需要使用 asp 获取 javascript 数组中的数据。如何获取数据并将其以这种格式放入 javascript 数组中。这个例子是 php .
<script>var chartdata=[{"values":[<?php $conn =mysql_connect("host","root","pass") or die ("we couldn't connect!");mysql_select_db("test");$rs = mysql_query("SELECT x1 FROM table") or die(mysql_error());while($row = mysql_fetch_array($rs)){echo $row['x'].',';}?>],}];</script>
我假设您了解 adodb 连接和记录集对象(如果您不知道,那里有很多教程),并且您已经创建了一个名为 conn
和 rs
的每个对象。
在经典ASP中,我会做这样的事情
<% Dim myarraystring, sql
sql = "SELECT x1 FROM table"
myarraystring = ""
rs.open sql,conn
Do While Not rs.eof
myarraystring = myarraystring & rs("x") & ","
rs.movenext
Loop
rs.close %>
<script>var chartdata=[{"values":[<%= myarraystring %>],}];</script>
连接字符串取决于所使用的驱动程序。这里有一个很好的资源,可以使用经典asp连接到MySQLhttp://www.connectionstrings.com/mysql/