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: 294

Filed under:
|
|
|
|

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:

  1. 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)?
  2. What is the best approach to handle situations like this, by using the advantages of .Net + protoype or jQuery?
  3. 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

Related posts about ASP.NET

Related posts about jQuery