Podcast
Questions and Answers
What does the acronym AJAX stand for?
What does the acronym AJAX stand for?
What is the primary purpose of the XMLHttpRequest object in AJAX?
What is the primary purpose of the XMLHttpRequest object in AJAX?
Who introduced AJAX to the world in 2005?
Who introduced AJAX to the world in 2005?
What is a common misconception about AJAX?
What is a common misconception about AJAX?
Signup and view all the answers
What is the purpose of AJAX in web development?
What is the purpose of AJAX in web development?
Signup and view all the answers
When was the first draft of the XMLHttpRequest object specification released by the W3C?
When was the first draft of the XMLHttpRequest object specification released by the W3C?
Signup and view all the answers
Which of the following is the purpose of the onreadystatechange property?
Which of the following is the purpose of the onreadystatechange property?
Signup and view all the answers
What is the status code for 'Page not found'?
What is the status code for 'Page not found'?
Signup and view all the answers
What is the purpose of the xhttp.open() method?
What is the purpose of the xhttp.open() method?
Signup and view all the answers
What is the value of the readyState property when the request is finished and the response is ready?
What is the value of the readyState property when the request is finished and the response is ready?
Signup and view all the answers
What is the purpose of the xhttp.send() method?
What is the purpose of the xhttp.send() method?
Signup and view all the answers
What is the purpose of the abort() method in an XMLHttpRequest object?
What is the purpose of the abort() method in an XMLHttpRequest object?
Signup and view all the answers
Which property of the XMLHttpRequest object holds the status of the request?
Which property of the XMLHttpRequest object holds the status of the request?
Signup and view all the answers
What is the purpose of the open() method in an XMLHttpRequest object?
What is the purpose of the open() method in an XMLHttpRequest object?
Signup and view all the answers
What is the purpose of the setRequestHeader() method in an XMLHttpRequest object?
What is the purpose of the setRequestHeader() method in an XMLHttpRequest object?
Signup and view all the answers
What is the purpose of the send() method in an XMLHttpRequest object when used with a string parameter?
What is the purpose of the send() method in an XMLHttpRequest object when used with a string parameter?
Signup and view all the answers
What is the value of the status property in an XMLHttpRequest object when the request is successful?
What is the value of the status property in an XMLHttpRequest object when the request is successful?
Signup and view all the answers
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 thereadyState
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()
andsend()
methods of the XMLHttpRequest object - Example:
xhttp.open("GET", "ajax_info.txt", true); xhttp.send();
- Use the
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
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.