0% found this document useful (0 votes)
21 views4 pages

AJAX

ajax cdac acts
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views4 pages

AJAX

ajax cdac acts
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

AJAX

Asynchronous JavaScript and XML (Ajax, or AJAX)


a web development technique in which a web app fetches content from the server
by making asynchronous HTTP requests,
and uses the new content to update the relevant parts of the page without
requiring a full page load.
This can make the page more responsive, because only the parts that need to be
updated are requested.

Ajax can be used to create single-page apps

Initially Ajax was implemented using the XMLHttpRequest interface,


but the fetch() API is more suitable for modern web applications:

XMLHttpRequest
objects are used to interact with servers
This enables a Web page to update just part of a page without disrupting what the
user is doing.
Despite its name, XMLHttpRequest can be used to retrieve any type of data, not just
XML.

Constructor
The constructor initializes an
XMLHttpRequest() XMLHttpRequest . It must be called
before any other method calls.
The XMLHttpRequest() constructor creates a new XMLHttpRequest .

AJAX 1
Syntax
new XMLHttpRequest()

Return value
A new XMLHttpRequest object.
The object must be prepared by at least calling open() to initialize it before
calling send() to send the request to the server.

Create an XMLHttpRequest Object

variable = new XMLHttpRequest();

XMLHttpRequest Object Methods


Method Description

new XMLHttpRequest() Creates a new XMLHttpRequest object

abort() Cancels the current request

getAllResponseHeaders() Returns header information

getResponseHeader() Returns specific header information

Specifies the requestmethod: the request type GET or


open(method, url, async, POSTurl: the file locationasync: true (asynchronous) or false
user, psw) (synchronous)user: optional user namepsw: optional
password

send() Sends the request to the serverUsed 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

AJAX 2
XMLHttpRequest Object Properties
Property Description

onload Defines a function to be called when the request is received (loaded)

Defines a function to be called when the readyState property


onreadystatechange
changes

Holds the status of the XMLHttpRequest.0: request not initialized1:


readyState server connection established2: request received3: processing
request4: request finished and response is ready

responseText Returns the response data as a string

responseXML Returns the response data as XML data

Returns the status-number of a request200: "OK"403:


status "Forbidden"404: "Not Found"For a complete list go to the Http
Messages Reference

statusText Returns the status-text (e.g. "OK" or "Not Found")

The onreadystatechange Property


The readyState property holds the status of the XMLHttpRequest.
The onreadystatechange property defines a callback function to be executed when
the readyState changes.

The status property and the statusText properties hold the status of the
XMLHttpRequest object.

Property Description

Defines a function to be called when the readyState property


onreadystatechange
changes

Holds the status of the XMLHttpRequest.0: request not initialized1:


readyState server connection established2: request received3: processing
request4: request finished and response is ready

200: "OK"403: "Forbidden"404: "Page not found"For a complete list


status
go to the Http Messages Reference

statusText Returns the status-text (e.g. "OK" or "Not Found")

AJAX 3
The onreadystatechange function is called every time the readyState changes.
When readyState is 4 and status is 200, the response is ready:

AJAX 4

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy