AJAXÂ ASP Example
15 April 2025 | Category: JavaScript
While ASP.NET is more common today, Classic ASP (using VBScript) is still used in legacy applications. Here, weâll use AJAX to fetch data from a Classic ASP page without reloading the webpage.
đ Project Files Structure
ajax-asp/
â
âââ index.html â Frontend with JavaScript
âââ server.asp â Classic ASP (VBScript) script for backend
đ 1. index.html
â HTML + AJAX Request
<!DOCTYPE html>
<html>
<head>
<title>AJAX with ASP Example</title>
</head>
<body>
<h2>Get Server Date (Classic ASP)</h2>
<button onclick="getDate()">Click to Get Date</button>
<p id="result"></p>
<script>
function getDate() {
const xhr = new XMLHttpRequest();
xhr.open("GET", "server.asp", true);
xhr.onload = function () {
if (xhr.status === 200) {
document.getElementById("result").innerText = xhr.responseText;
} else {
document.getElementById("result").innerText = "Error loading data.";
}
};
xhr.send();
}
</script>
</body>
</html>
đ§âđ» 2. server.asp
â Classic ASP Code
<%
Response.ContentType = "text/plain"
Dim currentDate
currentDate = Now()
Response.Write "Server Date and Time: " & currentDate
%>
đ How It Works
- You click the button on the HTML page.
- JavaScript makes an AJAX
GET
request toserver.asp
. - Classic ASP responds with the current date and time.
- The result is displayed instantly without refreshing the page.
â Output (Example)
Server Date and Time: 4/14/2025 5:47:12 PM
đ§ Notes
- Make sure to run this on a server that supports Classic ASP (like IIS).
- File extension must be
.asp
for server-side execution. - Classic ASP uses VBScript syntax and runs only on Windows-based servers.
đĄ Bonus Idea
You can expand this to:
- Get database values using
ADODB.Connection
- Send POST requests with AJAX and use
Request.Form
in ASP - Create login validation and return JSON (text format)