Chapter 40: ASP AJAX
1. What does “ASP AJAX” actually mean?
ASP AJAX is not a built-in feature of Classic ASP.
It is a combination of:
- Classic ASP pages (.asp files) that return small pieces of HTML / JSON / XML instead of full pages
- JavaScript in the browser (usually with the free Microsoft AJAX Library or jQuery after ~2007) that makes asynchronous HTTP requests (XMLHttpRequest / XHR) to those ASP pages
- The result is partial page updates without full page reload — what people called “AJAX” (Asynchronous JavaScript And XML)
In simple words:
Classic ASP normally returns complete HTML pages. With AJAX → Classic ASP returns only a fragment (a table row, a dropdown list, a status message, JSON data) → JavaScript inserts/updates only that part of the page.
This made old ASP sites feel much more modern — no full refresh when adding to cart, filtering products, live search, auto-save forms, etc.
2. The Two Main Ways People Did “ASP AJAX” in Real Life (2006–2012)
| Era / Style | JavaScript library used | Return format from ASP | Typical file name pattern | Still seen in 2026 legacy code? |
|---|---|---|---|---|
| Early / Microsoft way (2006–2009) | Microsoft AJAX Library (UpdatePanel, ScriptManager) | HTML fragments or JSON | getdata.asp, ajax_handler.asp | Yes — many government/intranet sites |
| jQuery era (2008–2015) | jQuery + $.ajax / $.post / $.get | JSON (most popular) or HTML | api.asp, json.asp, action.asp | Very common in small-business sites |
W3Schools teaches mostly the early Microsoft way + simple XMLHttpRequest, so we will start there and then show the more common jQuery style.
3. Classic Example 1 – Simple Microsoft AJAX Style (UpdatePanel – very typical 2006–2009)
File: default.asp (main page)
|
0 1 2 3 4 5 6 |
<%@ Language=VBScript %> <% Option Explicit %> <!DOCTYPE html> <html> <head> <title>ASP AJAX Example</title> <!-- Microsoft AJAX Library (included with ASP.NET 3.5, but can be used with Classic ASP too) --> <script src="https://ajax.microsoft.com/ajax/beta/0911/Start.debug.js" type="text/javascript"></script> </head> <body> <h2>Live Clock (AJAX Update)</h2> <div id="clockArea"> Loading... </div> <script type="text/javascript"> Sys.Application.initialize(); function updateClock() { Sys.Net.WebServiceProxy.invoke( "gettime.asp", "GetCurrentTime", false, {}, function(result) { $get("clockArea").innerHTML = result; }, null, null, null ); } // Update every 5 seconds setInterval(updateClock, 5000); updateClock(); // initial call </script> </body> </html> |
File: gettime.asp (the AJAX endpoint)
|
0 1 2 3 4 5 6 |
<%@ Language=VBScript %> <% Option Explicit %> <% Response.ContentType = "text/plain" Response.Write Now() %> |
What happens:
- Browser loads default.asp
- JavaScript calls gettime.asp every 5 seconds
- gettime.asp returns only the current time (no HTML wrapper)
- JavaScript updates only the <div id=”clockArea”> — no full page reload
4. More Common Real-World Style (jQuery + JSON – 2008–2015)
File: products.asp (main page)
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
<!DOCTYPE html> <html> <head> <title>Product Filter</title> <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script> </head> <body> <h2>Products</h2> Category: <select id="category"> <option value="">All</option> <option value="1">Biryani</option> <option value="2">Haleem</option> <option value="3">Desserts</option> </select> <div id="productList"> Loading products... </div> <script> $(document).ready(function() { $("#category").change(function() { var cat = $(this).val(); $.getJSON("getproducts.asp", { category: cat }, function(data) { var html = "<table border='1'><tr><th>Name</th><th>Price</th></tr>"; $.each(data, function(i, item) { html += "<tr><td>" + item.Name + "</td><td>₹" + item.Price + "</td></tr>"; }); html += "</table>"; $("#productList").html(html); }); }); // Initial load $("#category").trigger("change"); }); </script> </body> </html> |
File: getproducts.asp (the AJAX handler – returns JSON)
|
0 1 2 3 4 5 6 |
<%@ Language=VBScript %> <% Option Explicit %> <% Response.ContentType = "application/json" Response.Charset = "utf-8" Dim catID catID = Trim(Request("category")) Dim sql sql = "SELECT ProductName, UnitPrice FROM Products" If catID <> "" Then sql = sql & " WHERE CategoryID = " & catID End If sql = sql & " ORDER BY ProductName" ' Dummy data simulation (real code would use ADODB) Dim json json = "[" json = json & "{""Name"":""Hyderabadi Biryani"",""Price"":399}," json = json & "{""Name"":""Mutton Haleem"",""Price"":450}" json = json & "]" Response.Write json %> |
What happens:
- User changes dropdown → jQuery sends GET request to getproducts.asp?category=2
- ASP returns pure JSON array
- jQuery builds HTML table from JSON → updates only #productList div
- No full page refresh — feels like a modern single-page app
5. Security & Best Practice Warnings (Very Important in 2026)
- Never trust AJAX input — always validate/sanitize on server (Trim, CLng, Replace for SQL injection)
- Always use Server.HTMLEncode when returning HTML fragments
- JSON output → set Response.ContentType = “application/json” and Response.Charset = “utf-8”
- CORS issues → rare in same-domain AJAX, but if calling external APIs → need headers
- No CSRF protection in basic Classic ASP AJAX → add tokens for POST actions
- Logging → log AJAX calls — old sites were often attacked via open AJAX endpoints
6. Teacher Summary – ASP AJAX in Classic ASP
ASP AJAX means:
- Classic ASP pages returning small fragments (HTML, JSON, XML) instead of full pages
- Browser JavaScript (Microsoft AJAX Library or jQuery) making asynchronous requests (XMLHttpRequest, $.getJSON, $.post)
- Updating only part of the page (div, table, dropdown) without reload
- Two main styles:
- Early: Microsoft AJAX Library + UpdatePanel / WebMethods
- Later (more common): jQuery $.ajax / $.get / $.post + JSON responses
- Endpoints usually named getdata.asp, ajax.asp, api.asp, action.asp
- Huge performance & user-experience win over full postbacks
- Very common in Indian legacy business/intranet/e-commerce sites 2008–2015
This is how Classic ASP sites got “AJAX superpowers” — and many legacy systems still use exactly this pattern in 2026.
Next class?
- Want a full live search example (type in box → instant results)?
- Or add-to-cart without refresh with AJAX + Session?
- Or compare Classic ASP AJAX vs modern ASP.NET Core AJAX / fetch?
- Or move to the next W3Schools topic (ASP Cookies again or ASP Sessions)?
Just tell me — I’m here! 🚀🇮🇳 Keep learning strong, Webliance! 😊
