Best practices: Ajax and server side scripting with stored procedures
- by Luka Milani
I need to rebuild an old huge website and probably to port everyting to ASP.NET and jQuery and I would like to ask for some suggestion and tips. Actually the website uses:
Ajax (client site with prototype.js)
ASP (vb script server side)
SQL Server 2005
IIS 7 as web server
This website uses hundred of stored procedures and the requests are made by an ajax call and only 1 ASP page that contain an huge select case
Shortly an example:
JAVASCRIPT + PROTOTYPE:
var data = {
action: 'NEWS',
callback: 'doNews',
param1: $('text_example').value,
......: ..........};
AjaxGet(data); // perform a call using another function + prototype
SERVER SIDE ASP:
<% ......
select case request("Action")
case "NEWS"
With cmmDB
.ActiveConnection = Conn
.CommandText = "sp_NEWS_TO_CALL_for_example"
.CommandType = adCmdStoredProc
Set par0DB = .CreateParameter("Param1", adVarchar, adParamInput,6)
Set par1DB = .CreateParameter(".....", adInteger, adParamInput)
' ........ ' can be more parameters
.Parameters.Append par0DB
.Parameters.Append par1DB
par0DB.Value = request("Param1")
par1DB.Value = request(".....")
set rs=cmmDB.execute
RecodsetToJSON rs, jsa ' create JSON response using a sub
End With
.... %>
So as you can see I have an ASP page that has a lot of CASE and this page answers to all the ajax request in the site.
My question are:
Instead of having many CASES is it possible to create dynamic vb code that parses the ajax request and creates dynamically the call to the desired SP (also implementing the parameters passed by JS)?
What is the best approach to handle situations like this, by using the advantages of .Net + protoype or jQuery?
How the big sites handle situation like this? Do they do it by creating 1 page for request?
Thanks in advance for suggestion, direction and tips.