Virtually all of my server access is via AJAX... my server side files open a connection to my sql-server database and either write to or read from the current table(s).
I am saving my data in my sql-server table as JSON strings. For example:
[ {"score":"game","bet":"20"},
{"score":0,"bet":"10"},
{"score":1,"bet":"11"},
{"score":2,"bet":"12"},
{"score":3,"bet":"13"},
{"score":4,"bet":"14"},
{"score":5,"bet":"15"},
{"score":6,"bet":"16"},
{"score":7,"bet":"17"},
{"score":8,"bet":"18"},
{"score":9,"bet":"19"}
]
I have found that I need to do some validation and verification on the server. Ideally I'd like to pull this string out of the table, convert it to JSON (via JSON.Parse() I presume) perform the validation/verification and then make the response back to the client depending on the result.
I have looked at Node.js but I am not in a place to move my entire server from IIS to Node.js. Ideally I'd like to be able to just process javascript inside my standard ASP pages.
* Friday 12/13/2013 ***********
Here is most of the source code from the file being called by AJAX:
<%@LANGUAGE="JAVASCRIPT"%>
<script runat="server" src="scripts/json2.js"></script>
<%
var JSONstr;
var GridId;
var password;
var where;
var adoConn;
var adoComm;
var adoRS;
var json;
adoConn = Server.CreateObject("ADODB.Connection");
adoComm = Server.CreateObject("ADODB.Command");
adoRS = Server.CreateObject("ADODB.Recordset");
adoConn.ConnectionString = footballConnStr;
adoConn.Open();
GridId=Request.Form('GridId');
where = "Id = '" +GridId +"'"
password=Request.QueryString('password');
adoRS.ActiveConnection = adoConn;
adoRS.CursorType = 3; // So I can use RecordCount Property
adoRS.Source="SELECT GridBets FROM _Games WHERE " +where
// ** this is my little test to see if the JSON object from the JSON2.js is getting loaded
json = {};
JSONstr = JSON.stringify(json); // it is failing on this line...
// **
adoRS.Open();
var rslt = "{ digits:" +adoRS('GridBets') +"}";
adoRS.Close();
Response.Write( rslt );
Response.End();
/*
Your best bet is to use a JSON library for ASP. You haven't indicated whether or not you're using classic ASP though?
Some options for ASP.NET:
There are also a plethora of similar questions already on SO: