SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question How do I access a ASP/VB method from jScript/Ajax

    I have a web site currently written using ASP and Visual Basic. I want to rewrite the browser interface to use jQuery/Html/CSS etc however I still want to use the server side VB code to access the database. The server side code resides in www.mywebsite.com\app_code\clsGetData.vb

    My question is this. Is it possible to use jQuery.ajax to execute a method in my VB object and return the result and if so what would the jScript code look like?

    Many thanks in advance for any hints! Don

  2. #2
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can "post" the data to the target url

    google for :

    jquery post data

  3. #3
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    After hours of messing about I have finally realized that when an Ajax browser client requests data from the server it is expecting a page of html. The server code creates the page with the data to be sent to the client/browser. Now that I understand this concept my sample app is working fine.

    In my defense I kept thinking that Ajax had the smarts to do remote procedure calls to classes/methods on the server. I used to work with DCE, the Distributed Computing Environment which could do this.

    Ajax is therefore much simplier and very cool indeed. This interface is very clean.

    Am I still confused ?

  4. #4
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Here are the code snippets I used to interface jScript and VB/ASP.

    The jScript
    $("a#runSample1").click(function () {
    // see http://api.jquery.com/jQuery.post/
    $.post("GetServerValues.aspx", { myAjax: "AjaxValues=1,2,3,4" }, function (response) {
    alert(response);
    });
    });

    The VB code in GetServerValues.aspx.vb
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim iParamCnt As Short
    Dim iParam As Short
    Dim sParamValues As String
    Dim sParamValue As String
    Response.Expires = -1
    Response.ContentType = "text/plain"
    iParamCnt = Request.Params.Count
    sParamValues = ""
    If iParamCnt = 0 Then
    sParamValues = "No Parameters Passed"
    Else
    For iParam = 0 To iParamCnt - 1
    sParamValue = Request.Params.Item(iParam)
    'identify value passed via the ajax post method
    If InStr(sParamValue, "AjaxValues") = 1 Then
    sParamValues &= "(" & sParamValue & ") "
    End If
    Next
    End If
    Response.Write("Ajax values passed to server are = " & sParamValues)
    Response.End()
    End Sub

    Any comments, suggestions for improvement ?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •