Previous Next

Thread: Using Ajax with Classic ASP

Last post 05-12-2008 10:16 PM by MyronCope. 6 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (7 items)

Sort Posts:

  • 05-11-2008, 11:43 AM

    • MyronCope
    • Top 100 Contributor
    • Joined on 02-07-2005, 4:30 AM
    • Posts 21
    • MyronCope

    Using Ajax with Classic ASP

    I have 2 comboboxes on an ASP page and I need the following behavior:

    1. user selects a value on combobox1

    2.  this fires a javascript that uses Ajax to call some VBscript, I will call it queryDB()

    3.  the VBScript function queryDB() returns a recordset of records from the database

    4. bind the recordset to ComboBox2

    The main thing that I'm stuck on is part 2, using Ajax to call a VBScript function.  I now know I have to use some kind of Ajax because the page cannot postback.  Does anyone know how to do this?  any code samples would be great.

    also is it possible to use a recordset or do i have to return the data in xml form?  I posted a similar question already but I am posting this because I realize that I did not mention Ajax in my other initial post and this is the key point that I need to figure out, how to use Ajax with Classic ASP.

    thanks

  • 05-11-2008, 2:12 PM In reply to

    Re: Using Ajax with Classic ASP

    ASP doesn't work like ASP.NET.  Write the entire thing as ASP or move to ASP.NET.  Frankly, it doesn't sound like you should need to shell to an external VBScript just to query a database anyway.

    Jeff

    Look for Wrox's new book Professional IIS 7 in your local bookstore, or order now at Amazon.com
  • 05-12-2008, 8:48 AM In reply to

    • MyronCope
    • Top 100 Contributor
    • Joined on 02-07-2005, 4:30 AM
    • Posts 21
    • MyronCope

    Re: Using Ajax with Classic ASP

    The page is in classic ASP, I cannot change this. 

    Also, the requirement states that the page cannot refresh so I assume that I will have to implement some Ajax like coding there.

    If you know of another way that I can accomplish this I would be thrilled to hear about it.

  • 05-12-2008, 9:03 AM In reply to

    • tomkmvp
    • Top 10 Contributor
    • Joined on 03-20-2003, 10:27 AM
    • Princeton, NJ
    • Posts 3,214
    • IIS MVPs
    • tomkmvp

    Re: Using Ajax with Classic ASP

    How much data are we talking about?  One technique is to load all of the data at once into the client-side code of the page. Take a look at some of the examples here:
    http://msdn.microsoft.com/en-us/library/ms531388(vs.85).aspx

  • 05-12-2008, 9:10 AM In reply to

    • MyronCope
    • Top 100 Contributor
    • Joined on 02-07-2005, 4:30 AM
    • Posts 21
    • MyronCope

    Re: Using Ajax with Classic ASP

    not too much data but here is the situation:

    ComboBox1 can be loaded during pageload.

    but ComboBox2 values must be loaded when you change ComboBox2 because the values in ComboBox2 are dependent on what you choose in ComboBox1.

    I guess you can think of it like this:

    ComboBox1 could be states in the US.  When you select a state it will show corresponding cities that are in that selected state in ComboBox2.

  • 05-12-2008, 9:17 AM In reply to

    • tomkmvp
    • Top 10 Contributor
    • Joined on 03-20-2003, 10:27 AM
    • Princeton, NJ
    • Posts 3,214
    • IIS MVPs
    • tomkmvp

    Re: Using Ajax with Classic ASP

    Understood.

    If you can't refresh then you have two options:

    1)  my link above on DHTML and data binding

    2)  AJAX.  Have you seen this?
    http://www.google.com/search?sourceid=navclient&ie=UTF-8&rls=GGLG,GGLG:2006-01,GGLG:en&q=ajax+with+classic+asp

  • 05-12-2008, 10:16 PM In reply to

    • MyronCope
    • Top 100 Contributor
    • Joined on 02-07-2005, 4:30 AM
    • Posts 21
    • MyronCope

    Re: Using Ajax with Classic ASP

    Tom,

    thanks for your feedback.  I got it working! I pretty much followed this page, their ajax tutorial is great, highly recommended:

    http://www.w3schools.com/ajax/ajax_database.asp

     I followed this exactly except for the asp page (think the example is called getcustomer.asp), instead of writing out the values I loop through each record and create a combobox option for each record returned:

    <CODE>
    response.Write("<select>")

    do until rs.EOF      response.Write("<option value=" & rs("ID") & ">")

         response.Write(rs("City"))    

         response.Write("</option>")

    rs.MoveNext

    loop

    response.Write("</select>")

    </CODE>

    Otherwise my code is the same (except of course changing page names and similar things).

    If anyone wants to do this the link above should help you but let me know by posting here if you have any questions.

Page 1 of 1 (7 items)
Page view counter