Best practices: Ajax and server side scripting with stored procedures
Posted
by
Luka Milani
on Programmers
See other posts from Programmers
or by Luka Milani
Published on 2012-07-17T15:17:46Z
Indexed on
2012/09/19
21:50 UTC
Read the original article
Hit count: 415
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 2005IIS 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
CASESis it possible to create dynamicvbcode that parses theajaxrequest 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.
© Programmers or respective owner