听起来您需要使用经典asp生成JSON代码。有一些JSON类可用于经典ASP(
see here
试试这样的。。。
events.asp:
<%
Response.ContentType = "application/json"
Dim gobjConn, grs, gsConnect, gsSQL, theData, r, Area
' if you're getting the area int from the querystring it's wise to
' check it's actually an int before inserting it into your SQL
Area = request.QueryString("Area")
if NOT isNumeric(Area) then
Area = 1 ' set a default
'response.End() ' or just use response.End() to stop the script
else
Area = int(Area)
end if
Set gobjConn = Server.CreateObject("ADODB.Connection")
Set grs = Server.CreateObject("ADODB.Recordset")
gsConnect = "Driver={SQL Server};Server=Server;Database=mydb;uid=uid,pw=pw"
gobjConn.Open gsConnect
gsSQL = "SELECT ID,[Event Start], [Event End] FROM Events WHERE Area = " & Area
Set grs = gobjConn.Execute(gsSQL)
if NOT grs.EOF then
' Use GetRows() to convert the recordset to to a 2D array
theData = grs.getRows()
' start to build the JSON
response.write "[" & VBcrlf
for r = 0 to uBound(theData,2)
' loop through the events
response.write " {" & VBcrlf
response.write " ""id"": """ & theData(0,r) & """," & VBcrlf
' If you want to include a title you would need to escape the text:
' response.write " ""title"": """ & JSONEncode(theData(3,r)) & """," & VBcrlf
response.write " ""start"": """ & theData(1,r) & """," & VBcrlf
response.write " ""end"": """ & theData(2,r) & """" & VBcrlf
if r = uBound(theData,2) then
' end of events, no comma
response.write " }" & VBcrlf
else
response.write " }," & VBcrlf
end if
next
response.write "]"
else
' no events
end if
grs.close() : set grs = nothing ' close the recordset
gobjConn.close() : set gobjConn = nothing ' close the connection
' Use this function to escape JSON text
Function JSONEncode(ByVal val)
val = Replace(val, "\", "\\")
val = Replace(val, """", "\""")
val = Replace(val, Chr(8), "\b")
val = Replace(val, Chr(12), "\f")
val = Replace(val, Chr(10), "\n")
val = Replace(val, Chr(13), "\r")
val = Replace(val, Chr(9), "\t")
JSONEncode = Trim(val)
End Function
%>
JSON class
由@lankymart链接:
<!--#include file = "jsonObject.class.asp" -->
<%
Response.ContentType = "application/json"
Dim gobjConn, grs, gsConnect, gsSQL, Area
' if you're getting the area int from the querystring it's wise to
' check it's actually an int before inserting it into your SQL
Area = request.QueryString("Area")
if NOT isNumeric(Area) then
Area = 0 ' set a default
'response.End() ' or just use response.End() to stop the script
else
Area = int(Area)
end if
Set gobjConn = Server.CreateObject("ADODB.Connection")
Set grs = Server.CreateObject("ADODB.Recordset")
gsConnect = "Driver={SQL Server};Server=Server;Database=mydb;uid=uid,pw=pw"
gobjConn.Open gsConnect
gsSQL = "SELECT ID,[Event Start], [Event End] FROM Events WHERE Area = " & Area
Set grs = gobjConn.Execute(gsSQL)
set JSON = New JSONarray
JSON.LoadRecordset grs
JSON.Write()
set JSON = nothing
grs.close() : set grs = nothing ' close the recordset
gobjConn.close() : set gobjConn = nothing ' close the connection
%>
events: {
url: 'events.asp',
error: function() {
$('#script-warning').show();
}
},