我需要使用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>发布于 2016-01-18 13:41:50
我假设您了解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 MySQL连接到http://www.connectionstrings.com/mysql/
https://stackoverflow.com/questions/34849202
复制相似问题