AJAX ASP

AJAX with ASP

Just like PHP, you can use AJAX to communicate with an ASP (Active Server Pages) backend.

Both Classic ASP and modern ASP.NET handle AJAX HTTP requests identically to PHP.


The Frontend Code

The JavaScript code remains exactly the same as the PHP example in the previous chapter.

The only difference is the file extension you target in the open() method.

Instead of requesting gethint.php, you request gethint.asp.


Sending the Request

You utilize the onkeyup event on an input box to capture user keystrokes.

The XMLHttpRequest object instantly fires those keystrokes to the ASP server.

ASP Frontend Example:

function showHint(str) {
  if (str.length === 0) {
    document.getElementById("txtHint").innerHTML = "";
    return;
  }
  const xhttp = new XMLHttpRequest();
  xhttp.onload = function() {
    document.getElementById("txtHint").innerHTML = this.responseText;
  }
  

// Notice the file extension is now .asp! xhttp.open("GET", "gethint.asp?q=" + str); xhttp.send(); }


The ASP Backend Code

Inside the gethint.asp file, you write VBScript or C# to process the incoming data.

The server reads the query string using Request.QueryString("q").

It matches the string against an array of data, and uses Response.Write to send the result back to the browser!


Universal Compatibility

AJAX is entirely backend-agnostic.

Whether your server runs PHP, ASP, Node.js, or Python, the JavaScript implementation never changes.

This universal compatibility makes AJAX incredibly powerful and timeless.


Exercise 1 of 1

?

Does the JavaScript AJAX syntax change depending on whether the server runs PHP or ASP?