๐ŸŒ ASP.NET Web Services & AJAX
Estimated reading: 4 minutes 294 views

Classic ASP โ€“ AJAX Integration โ€“ Enabling Asynchronous Server Calls in Legacy Web Apps

Introduction โ€“ Why Use AJAX in Classic ASP?

While Classic ASP is a server-side scripting environment that executes VBScript or JScript to render dynamic web pages, it traditionally requires full page reloads for every server interaction. Integrating AJAX (Asynchronous JavaScript and XML) allows Classic ASP pages to send and receive data from the server without refreshing the page, providing a smoother and faster user experience.

In this guide, youโ€™ll learn:

  • How to implement AJAX with Classic ASP using JavaScript and XMLHttpRequest
  • Real-world examples of AJAX calls to .asp pages
  • How to handle AJAX response and update the DOM dynamically
  • Limitations and best practices for AJAX in Classic ASP

What Is AJAX?

AJAX is a browser-based technique using:

  • JavaScript to send HTTP requests
  • XMLHttpRequest (or fetch()) to call the server
  • Response parsing (plain text, JSON, XML)
  • DOM updates without full-page reloads

This works well with Classic ASP by targeting .asp endpoints.


Example โ€“ AJAX Call to a Classic ASP Page

HTML + JavaScript Page (Client Side)

<!DOCTYPE html>
<html>
<head>
  <title>Classic ASP + AJAX Example</title>
  <script>
    function fetchData() {
      var xhr = new XMLHttpRequest();
      xhr.open("GET", "getdata.asp", true);
      xhr.onreadystatechange = function() {
        if (xhr.readyState === 4 && xhr.status === 200) {
          document.getElementById("result").innerHTML = xhr.responseText;
        }
      };
      xhr.send();
    }
  </script>
</head>
<body>
  <h2>AJAX in Classic ASP</h2>
  <button onclick="fetchData()">Load Data</button>
  <div id="result">Waiting for server...</div>
</body>
</html>

getdata.asp (Server Side โ€“ Classic ASP)

<%
Response.ContentType = "text/plain"
Response.Write("Server Time: " & Now())
%>

Output:
When the user clicks the button, the page dynamically updates to:
Server Time: 6/11/2025 4:40:00 PM


Example โ€“ AJAX POST to Classic ASP

JavaScript (POST)

function sendFormData() {
  var xhr = new XMLHttpRequest();
  xhr.open("POST", "submitform.asp", true);
  xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

  xhr.onreadystatechange = function () {
    if (xhr.readyState === 4 && xhr.status === 200) {
      alert("Response: " + xhr.responseText);
    }
  };

  var data = "username=admin&password=1234";
  xhr.send(data);
}

submitform.asp

<%
username = Request.Form("username")
password = Request.Form("password")

If username = "admin" And password = "1234" Then
  Response.Write("Login Success")
Else
  Response.Write("Invalid Credentials")
End If
%>

Response Types โ€“ Text, JSON, and XML

Classic ASP supports:

  • Text responses: Response.Write("text")
  • JSON responses: via manual string concatenation
  • XML responses: via Response.ContentType = "text/xml"

Example JSON output in user.asp:

<%
Response.ContentType = "application/json"
Response.Write("{""name"":""John"",""role"":""Admin""}")
%>

Best Practices for AJAX in Classic ASP

Do:

  • Set ContentType headers correctly (text/plain, application/json)
  • Sanitize inputs received via AJAX
  • Return minimal payloads for fast response

Avoid:

  • Complex HTML construction in Classic ASP
  • Mixing client-side JS with too much server-side inline script
  • Using AJAX for sensitive actions without CSRF protection or HTTPS

Summary โ€“ Recap & Next Steps

AJAX breathes new life into Classic ASP by enabling real-time, dynamic behavior without page reloads. Using XMLHttpRequest or fetch(), you can seamlessly call .asp endpoints and update the UI for improved user experience.

Key Takeaways:

  • AJAX helps Classic ASP apps act like modern web apps
  • Use XMLHttpRequest for GET/POST to .asp pages
  • Always handle security and performance for AJAX endpoints

Real-world Use Cases:

  • Live data refresh (stock price, server time)
  • Form validation or login without page reload
  • Dynamic dropdowns or content loading

FAQs โ€“ Classic ASP with AJAX


Can I use jQuery AJAX with Classic ASP?
Yes. Use $.ajax() or $.post() to call .asp endpoints and handle responses easily.


Does Classic ASP support JSON natively?
No. You’ll need to manually build JSON strings or use scripting libraries like JScript with Scripting.Dictionary.


How to debug AJAX errors in Classic ASP?
Use browser dev tools (F12 โ†’ Network tab) to inspect requests, response status, and content.


Can I call ASP pages from other domains?
Only if CORS (Cross-Origin Resource Sharing) is enabled via headers like:

Response.AddHeader "Access-Control-Allow-Origin", "*"

Share Now :
Share

๐Ÿ”ƒ Classic ASP โ€“ AJAX (merged topic)

Or Copy Link

CONTENTS
Scroll to Top