Introduction to AJAX: What is AJAX and How it Works

RevolutionaryAppleTree avatar
RevolutionaryAppleTree
·
·
Download

Start Quiz

Study Flashcards

17 Questions

What does the acronym AJAX stand for?

Asynchronous JavaScript and XML

What is the primary purpose of the XMLHttpRequest object in AJAX?

To request data from a web server

Who introduced AJAX to the world in 2005?

Jesse James Garrett

What is a common misconception about AJAX?

It only uses XML to transport data

What is the purpose of AJAX in web development?

To allow web pages to be updated asynchronously

When was the first draft of the XMLHttpRequest object specification released by the W3C?

5th April 2006

Which of the following is the purpose of the onreadystatechange property?

To define a function to be executed when the readyState changes.

What is the status code for 'Page not found'?

404

What is the purpose of the xhttp.open() method?

To specify the request type and URL.

What is the value of the readyState property when the request is finished and the response is ready?

4

What is the purpose of the xhttp.send() method?

To send the request to the server.

What is the purpose of the abort() method in an XMLHttpRequest object?

To cancel the current request

Which property of the XMLHttpRequest object holds the status of the request?

readyState

What is the purpose of the open() method in an XMLHttpRequest object?

To specify the request method and URL

What is the purpose of the setRequestHeader() method in an XMLHttpRequest object?

To add a label/value pair to the header

What is the purpose of the send() method in an XMLHttpRequest object when used with a string parameter?

To send the request to the server for a POST request

What is the value of the status property in an XMLHttpRequest object when the request is successful?

200

Study Notes

XMLHttpRequest Object

  • Syntax for creating an XMLHttpRequest object: variable = new XMLHttpRequest()

XMLHttpRequest Object Methods

  • abort(): Cancels the current request
  • getAllResponseHeaders(): Returns header information
  • getResponseHeader(): Returns specific header information
  • open(method, url, async, user, psw): Specifies the request
    • method: the request type (GET or POST)
    • url: the file location
    • async: true (asynchronous) or false (synchronous)
    • user: optional user name
    • psw: optional password
  • send(): Sends the request to the server (used for GET requests)
  • send(string): Sends the request to the server (used for POST requests)
  • setRequestHeader(): Adds a label/value pair to the header to be sent

XMLHttpRequest Object Properties

  • onreadystatechange: Defines a function to be called when the readyState property changes
  • readyState: Holds the status of the XMLHttpRequest
    • 0: request not initialized
    • 1: server connection established
    • 2: request received
    • 3: processing request
    • 4: request finished and response is ready
  • responseText: Returns the response data as a string
  • responseXML: Returns the response data as XML data
  • status: Returns the status-number of a request
    • 200: "OK"
    • 403: "Forbidden"
    • 404: "Not Found"
  • statusText: Returns the status-text (e.g. "OK" or "Not Found")

Introduction to AJAX

  • AJAX stands for Asynchronous JavaScript and XML
  • AJAX is not a programming language, but a combination of:
    • Browser built-in XMLHttpRequest object
    • JavaScript and HTML DOM
  • AJAX allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes

History of AJAX

  • Jesse James Garrett introduced AJAX to the world on 18th February 2005
  • W3C released the first draft of XMLHttpRequest object specifications on 5th April 2006

How AJAX Works

  • Uses the XMLHttpRequest object to exchange data with a server behind the scenes
  • Steps to send a request to a server:
    • Use the open() and send() methods of the XMLHttpRequest object
    • Example: xhttp.open("GET", "ajax_info.txt", true); xhttp.send();

Test your knowledge of AJAX, a technology that allows for asynchronous web page updates. Learn about the XMLHttpRequest object, how AJAX works, and what AJAX stands for. Discover the basics of AJAX and its applications.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Use Quizgecko on...
Browser
Browser