我需要使用asp.net获取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 连接到 MySQL http://www.connectionstrings.com/mysql/
关于javascript - 如何在asp.net中获取数组中的值(或者asp-classic会更好),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34849202/