AJAX allows web pages to be updated asynchronously by exchanging data with a web server in the background without reloading the entire page. It uses the XMLHttpRequest object to make requests and JavaScript and DOM to display or use the returned data. The XMLHttpRequest object can be used to request data from a web server and update parts of a web page without reloading. It has methods like open(), send(), setRequestHeader(), and properties like onreadystatechange that define functions to execute when the ready state changes.
The document provides an overview of AJAX (Asynchronous JavaScript and XML), including:
- AJAX allows web pages to be updated asynchronously by exchanging data with a server in the background without reloading the entire page.
- It uses a combination of XMLHttpRequest object, JavaScript, DOM, and often XML to retrieve data from the server and update parts of the page.
- The XMLHttpRequest object handles asynchronous requests in the background. Readystatechange events and response properties are used to update page elements with the server response.
- Common AJAX techniques like GET and POST requests, callbacks, and examples are explained.
The XMLHttpRequest object is used to exchange data with a server asynchronously without reloading the page. It creates an XMLHttpRequest object using new XMLHttpRequest() or new ActiveXObject for older browsers, and sends a request to the server using open() and send() methods. The onreadystatechange event handler processes the server response when readyState changes to 4. The response is retrieved using responseText or responseXML properties. AJAX can be used to dynamically update parts of a page or retrieve data from a server database without reloading.
This document provides an overview of AJAX (Asynchronous JavaScript and XML) and web services. It defines AJAX as a group of interrelated technologies that allow asynchronous data retrieval without page reloads. The key aspects covered include the XMLHttpRequest object for asynchronous client-server communication, callback functions, properties and methods. It also introduces web services, describing how to create, publish, test and consume a web service, as well as using SOAP.
Ajax allows for asynchronous data exchange in the background without reloading the webpage. It uses JavaScript and XMLHttpRequest objects to make requests to the server and update portions of the webpage. The process involves creating an XMLHttpRequest object, opening a request with a method like GET and a URL, sending the request, handling the response, and updating the HTML page without reloading. Key properties and methods of the XMLHttpRequest object allow processing the asynchronous request and response. Ajax improves the user experience by updating parts of pages in the background without interfering with other actions on the page.
AJAX allows web pages to be updated asynchronously by exchanging small amounts of data with the server in the background without reloading the entire page. It uses a combination of XMLHttpRequest object, JavaScript, DOM, and XML to retrieve data from the server and update parts of the web page. The XMLHttpRequest object sends and receives data from the server in the background, and JavaScript code can access and use the received data to make changes on the web page via DOM without reloading.
The document discusses Ajax, including:
1) What Ajax is and how it allows web pages to update parts without reloading the whole page by exchanging small amounts of data with the server asynchronously.
2) The basic Ajax process involves using JavaScript to define a request object, initiate a request by setting a response handler and sending GET or POST data, and handling the response when ready by extracting the returned text or XML.
3) Examples of applications using Ajax include Google Maps, Gmail, YouTube, and Facebook tabs.
AJAX allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes without reloading the entire page. It uses a combination of technologies including XMLHttpRequest objects, JavaScript, DOM, and CSS. The XMLHttpRequest object sends and receives data from the server that can be used to update portions of a web page. This improves interactivity and allows for dynamic interfaces.
Ajax allows web pages to asynchronously update parts of a page by exchanging data with a server in the background without reloading the entire page. It uses a combination of technologies like XMLHttpRequest, JavaScript, CSS, and HTML to retrieve and display updated content from a web server. The XMLHttpRequest object is used to send and receive data from a server asynchronously by executing JavaScript code when new data is received without blocking other scripts or reloading the entire page.
The document provides an overview of AJAX (Asynchronous JavaScript and XML), including:
- AJAX allows web pages to be updated asynchronously by exchanging data with a server in the background without reloading the entire page.
- It uses a combination of XMLHttpRequest object, JavaScript, DOM, and often XML to retrieve data from the server and update parts of the page.
- The XMLHttpRequest object handles asynchronous requests in the background. Readystatechange events and response properties are used to update page elements with the server response.
- Common AJAX techniques like GET and POST requests, callbacks, and examples are explained.
The XMLHttpRequest object is used to exchange data with a server asynchronously without reloading the page. It creates an XMLHttpRequest object using new XMLHttpRequest() or new ActiveXObject for older browsers, and sends a request to the server using open() and send() methods. The onreadystatechange event handler processes the server response when readyState changes to 4. The response is retrieved using responseText or responseXML properties. AJAX can be used to dynamically update parts of a page or retrieve data from a server database without reloading.
This document provides an overview of AJAX (Asynchronous JavaScript and XML) and web services. It defines AJAX as a group of interrelated technologies that allow asynchronous data retrieval without page reloads. The key aspects covered include the XMLHttpRequest object for asynchronous client-server communication, callback functions, properties and methods. It also introduces web services, describing how to create, publish, test and consume a web service, as well as using SOAP.
Ajax allows for asynchronous data exchange in the background without reloading the webpage. It uses JavaScript and XMLHttpRequest objects to make requests to the server and update portions of the webpage. The process involves creating an XMLHttpRequest object, opening a request with a method like GET and a URL, sending the request, handling the response, and updating the HTML page without reloading. Key properties and methods of the XMLHttpRequest object allow processing the asynchronous request and response. Ajax improves the user experience by updating parts of pages in the background without interfering with other actions on the page.
AJAX allows web pages to be updated asynchronously by exchanging small amounts of data with the server in the background without reloading the entire page. It uses a combination of XMLHttpRequest object, JavaScript, DOM, and XML to retrieve data from the server and update parts of the web page. The XMLHttpRequest object sends and receives data from the server in the background, and JavaScript code can access and use the received data to make changes on the web page via DOM without reloading.
The document discusses Ajax, including:
1) What Ajax is and how it allows web pages to update parts without reloading the whole page by exchanging small amounts of data with the server asynchronously.
2) The basic Ajax process involves using JavaScript to define a request object, initiate a request by setting a response handler and sending GET or POST data, and handling the response when ready by extracting the returned text or XML.
3) Examples of applications using Ajax include Google Maps, Gmail, YouTube, and Facebook tabs.
AJAX allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes without reloading the entire page. It uses a combination of technologies including XMLHttpRequest objects, JavaScript, DOM, and CSS. The XMLHttpRequest object sends and receives data from the server that can be used to update portions of a web page. This improves interactivity and allows for dynamic interfaces.
Ajax allows web pages to asynchronously update parts of a page by exchanging data with a server in the background without reloading the entire page. It uses a combination of technologies like XMLHttpRequest, JavaScript, CSS, and HTML to retrieve and display updated content from a web server. The XMLHttpRequest object is used to send and receive data from a server asynchronously by executing JavaScript code when new data is received without blocking other scripts or reloading the entire page.
Ajax allows asynchronous communication between a browser and server to update parts of a web page without reloading the entire page. It uses a combination of technologies including JavaScript, HTML, CSS, XML, and HTTP. The XMLHttpRequest object is used to asynchronously send and receive data from a web server in the background without interfering with the display and behavior of the existing page. This allows for faster and more interactive web applications.
The document discusses a lecture on AJAX and JSON. It provides an introduction to AJAX, where and how it can be used, and how to combine AJAX with JSON. It then reviews JavaScript objects and JSON, and demonstrates how to make AJAX requests with simple JavaScript. The document outlines the steps to create an XMLHttpRequest object and make asynchronous requests. It also discusses properties and methods of the XMLHttpRequest object like open(), send(), status, and readyState. Finally, it provides examples of using AJAX to fetch JSON data and display it on a page.
AJAX stands for Asynchronous JavaScript And XML. It allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes, without interfering with the display and behavior of the existing page. AJAX uses XMLHttpRequest object to request data from the server and JavaScript is used to display or use the data. The steps include creating an XMLHttpRequest object, making a request to the server using open() and send() methods, monitoring the response using onreadystatechange event handler, and updating the webpage with the response data.
AJAX allows asynchronous communication between the browser and server without reloading the page. It uses the XMLHttpRequest object to make HTTP requests and retrieve data from the server in the background. This allows parts of the web page to be updated independently without interfering with the display and behavior of the existing page.
Ajax is a technique for creating faster and more responsive web applications by exchanging small amounts of data with the server asynchronously in the background without interfering with the display and behavior of the existing page. It uses a set of core technologies including JavaScript, HTML, CSS, XML, and the XMLHttpRequest object to retrieve data from the server and update parts of the web page without reloading the entire page. The key aspects are that it allows asynchronous JavaScript calls to the server in the background, receives a response containing data rather than a full page reload, and uses that data to update the currently loaded page.
AJAX allows for asynchronous data retrieval and updating of parts of a web page without reloading the entire page. It uses a combination of technologies including XML, JavaScript, CSS, HTML and the XMLHttpRequest object. The XMLHttpRequest object makes asynchronous HTTP requests to the server in the background and retrieves data from the server. This allows updating parts of the web page without interrupting the user's operation.
The document discusses Ajax (Asynchronous JavaScript And XML). It defines Ajax as a combination of technologies used to asynchronously exchange data between a browser and server behind the scenes without reloading the page. An example is provided demonstrating how to use the XMLHttpRequest object to request data from a server and update the HTML DOM without reloading the page. Key aspects of the XMLHttpRequest object like open(), send(), and onreadystatechange are explained.
AJAX is an acronym standing for Asynchronous JavaScript and XML and this technology helps us to load data from the server without a browser page refresh.
If you are new with AJAX, I would recommend you go through our Ajax Tutorial before proceeding further.
JQuery is a great tool which provides a rich set of AJAX methods to develop next generation web application.
The document discusses Asynchronous JavaScript and XML (AJAX) technology. It defines AJAX and explains its purpose is to update parts of a web page asynchronously without reloading the entire page. It describes the technologies used including JavaScript, XML, and server-side languages. It provides examples of how AJAX works and the processes involved, including using the XMLHttpRequest object to asynchronously send and receive data from the server in the background. The advantages and disadvantages of AJAX are also summarized.
The document discusses AJAX (Asynchronous JavaScript and XML), which allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes, without reloading the entire page. It provides an overview of the basic objects and steps needed to make AJAX work, including the XMLHttpRequest object, how servers respond, and using the response. It then contrasts the traditional synchronous web page model with AJAX's asynchronous approach. The document also covers the basics of writing AJAX applications, including creating XMLHttpRequest objects, sending requests, handling responses, and using properties and methods. Finally, it provides a skeleton for a general AJAX application and an example to get the time from the server without refreshing the whole page.
The document discusses Ajax and how it allows asynchronous communication with a server without reloading the entire web page. It covers the basic objects and methods needed, including the XMLHttpRequest object. The typical Ajax process involves creating an XMLHttpRequest object, sending it to the server, and triggering a response function when the server responds to update the display without reloading the page.
Ajax allows for asynchronous retrieval of data from a server in the background without reloading the page. It uses a combination of technologies like XMLHttpRequest, JavaScript, and DOM to make asynchronous calls to a server and update portions of a page without reloading. The document then provides an example of how an Ajax interaction works, from making an asynchronous request to a server to processing the response and updating the HTML DOM.
Ajax allows for asynchronous retrieval of data from a server in the background without reloading the page. It uses a combination of technologies like XMLHttpRequest, JavaScript, and DOM to make asynchronous calls to a server and update portions of a page without reloading. The document then provides an example of how an Ajax interaction works, from making an asynchronous request to a server to processing the response and updating the HTML DOM.
AJAX allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page. AJAX uses a combination of XMLHttpRequest objects, JavaScript, HTML and CSS. The XMLHttpRequest object is used to request data from the server after the page has loaded.
AJAX (Asynchronous JavaScript and XML) is a development technique for building interactive web applications. It allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes, without interfering with the display and behavior of the existing page. Some key uses of AJAX include real-time form validation, auto-completion of form fields, loading additional data without page refreshes, and implementing rich user interfaces with progress indicators and other controls. The core components that enable AJAX include HTML/XHTML for content display, CSS for presentation, DOM for dynamic display of information, XMLHttpRequest object for asynchronous data retrieval from the server, and JavaScript to bind everything together.
This document provides an introduction and overview of AJAX (Asynchronous JavaScript and XML), including what it is, how it works, advantages and disadvantages, methods for implementation, and examples of frameworks and applications that use AJAX techniques.
1) The document discusses Asynchronous JavaScript and XML (AJAX) which allows for asynchronous communication between a browser and server without requiring the user to wait for processing a request.
2) Traditional HTTP processing uses synchronous request-response pairs while AJAX uses asynchronous JavaScript calls to update portions of a page without refreshing.
3) The key aspects of AJAX covered are the XMLHttpRequest object, opening the object to specify the request, handling the response, and properties/methods of the object. Server-side code can also be invoked using AJAX.
Day 1 of 7-days "JavaScript and Rich User Interfaces" training for my colleagues. It covers XMLHttpRequest, iframe, img cookie transport, script transport, JSONP, comet.
The document provides an overview of AJAX and web services. It discusses AJAX architecture and how it uses XMLHttpRequest objects to asynchronously exchange data with web servers without reloading pages. It also covers web services, describing them as software modules that can be published, located, and invoked over a network to perform tasks. The key components of web services are defined as SOAP, WSDL, and UDDI, which handle messaging, description, and discovery.
Ajax allows asynchronous communication between a browser and server to update parts of a web page without reloading the entire page. It uses a combination of technologies including JavaScript, HTML, CSS, XML, and HTTP. The XMLHttpRequest object is used to asynchronously send and receive data from a web server in the background without interfering with the display and behavior of the existing page. This allows for faster and more interactive web applications.
The document discusses a lecture on AJAX and JSON. It provides an introduction to AJAX, where and how it can be used, and how to combine AJAX with JSON. It then reviews JavaScript objects and JSON, and demonstrates how to make AJAX requests with simple JavaScript. The document outlines the steps to create an XMLHttpRequest object and make asynchronous requests. It also discusses properties and methods of the XMLHttpRequest object like open(), send(), status, and readyState. Finally, it provides examples of using AJAX to fetch JSON data and display it on a page.
AJAX stands for Asynchronous JavaScript And XML. It allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes, without interfering with the display and behavior of the existing page. AJAX uses XMLHttpRequest object to request data from the server and JavaScript is used to display or use the data. The steps include creating an XMLHttpRequest object, making a request to the server using open() and send() methods, monitoring the response using onreadystatechange event handler, and updating the webpage with the response data.
AJAX allows asynchronous communication between the browser and server without reloading the page. It uses the XMLHttpRequest object to make HTTP requests and retrieve data from the server in the background. This allows parts of the web page to be updated independently without interfering with the display and behavior of the existing page.
Ajax is a technique for creating faster and more responsive web applications by exchanging small amounts of data with the server asynchronously in the background without interfering with the display and behavior of the existing page. It uses a set of core technologies including JavaScript, HTML, CSS, XML, and the XMLHttpRequest object to retrieve data from the server and update parts of the web page without reloading the entire page. The key aspects are that it allows asynchronous JavaScript calls to the server in the background, receives a response containing data rather than a full page reload, and uses that data to update the currently loaded page.
AJAX allows for asynchronous data retrieval and updating of parts of a web page without reloading the entire page. It uses a combination of technologies including XML, JavaScript, CSS, HTML and the XMLHttpRequest object. The XMLHttpRequest object makes asynchronous HTTP requests to the server in the background and retrieves data from the server. This allows updating parts of the web page without interrupting the user's operation.
The document discusses Ajax (Asynchronous JavaScript And XML). It defines Ajax as a combination of technologies used to asynchronously exchange data between a browser and server behind the scenes without reloading the page. An example is provided demonstrating how to use the XMLHttpRequest object to request data from a server and update the HTML DOM without reloading the page. Key aspects of the XMLHttpRequest object like open(), send(), and onreadystatechange are explained.
AJAX is an acronym standing for Asynchronous JavaScript and XML and this technology helps us to load data from the server without a browser page refresh.
If you are new with AJAX, I would recommend you go through our Ajax Tutorial before proceeding further.
JQuery is a great tool which provides a rich set of AJAX methods to develop next generation web application.
The document discusses Asynchronous JavaScript and XML (AJAX) technology. It defines AJAX and explains its purpose is to update parts of a web page asynchronously without reloading the entire page. It describes the technologies used including JavaScript, XML, and server-side languages. It provides examples of how AJAX works and the processes involved, including using the XMLHttpRequest object to asynchronously send and receive data from the server in the background. The advantages and disadvantages of AJAX are also summarized.
The document discusses AJAX (Asynchronous JavaScript and XML), which allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes, without reloading the entire page. It provides an overview of the basic objects and steps needed to make AJAX work, including the XMLHttpRequest object, how servers respond, and using the response. It then contrasts the traditional synchronous web page model with AJAX's asynchronous approach. The document also covers the basics of writing AJAX applications, including creating XMLHttpRequest objects, sending requests, handling responses, and using properties and methods. Finally, it provides a skeleton for a general AJAX application and an example to get the time from the server without refreshing the whole page.
The document discusses Ajax and how it allows asynchronous communication with a server without reloading the entire web page. It covers the basic objects and methods needed, including the XMLHttpRequest object. The typical Ajax process involves creating an XMLHttpRequest object, sending it to the server, and triggering a response function when the server responds to update the display without reloading the page.
Ajax allows for asynchronous retrieval of data from a server in the background without reloading the page. It uses a combination of technologies like XMLHttpRequest, JavaScript, and DOM to make asynchronous calls to a server and update portions of a page without reloading. The document then provides an example of how an Ajax interaction works, from making an asynchronous request to a server to processing the response and updating the HTML DOM.
Ajax allows for asynchronous retrieval of data from a server in the background without reloading the page. It uses a combination of technologies like XMLHttpRequest, JavaScript, and DOM to make asynchronous calls to a server and update portions of a page without reloading. The document then provides an example of how an Ajax interaction works, from making an asynchronous request to a server to processing the response and updating the HTML DOM.
AJAX allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page. AJAX uses a combination of XMLHttpRequest objects, JavaScript, HTML and CSS. The XMLHttpRequest object is used to request data from the server after the page has loaded.
AJAX (Asynchronous JavaScript and XML) is a development technique for building interactive web applications. It allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes, without interfering with the display and behavior of the existing page. Some key uses of AJAX include real-time form validation, auto-completion of form fields, loading additional data without page refreshes, and implementing rich user interfaces with progress indicators and other controls. The core components that enable AJAX include HTML/XHTML for content display, CSS for presentation, DOM for dynamic display of information, XMLHttpRequest object for asynchronous data retrieval from the server, and JavaScript to bind everything together.
This document provides an introduction and overview of AJAX (Asynchronous JavaScript and XML), including what it is, how it works, advantages and disadvantages, methods for implementation, and examples of frameworks and applications that use AJAX techniques.
1) The document discusses Asynchronous JavaScript and XML (AJAX) which allows for asynchronous communication between a browser and server without requiring the user to wait for processing a request.
2) Traditional HTTP processing uses synchronous request-response pairs while AJAX uses asynchronous JavaScript calls to update portions of a page without refreshing.
3) The key aspects of AJAX covered are the XMLHttpRequest object, opening the object to specify the request, handling the response, and properties/methods of the object. Server-side code can also be invoked using AJAX.
Day 1 of 7-days "JavaScript and Rich User Interfaces" training for my colleagues. It covers XMLHttpRequest, iframe, img cookie transport, script transport, JSONP, comet.
The document provides an overview of AJAX and web services. It discusses AJAX architecture and how it uses XMLHttpRequest objects to asynchronously exchange data with web servers without reloading pages. It also covers web services, describing them as software modules that can be published, located, and invoked over a network to perform tasks. The key components of web services are defined as SOAP, WSDL, and UDDI, which handle messaging, description, and discovery.
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSIJNSA Journal
The smart irrigation system represents an innovative approach to optimize water usage in agricultural and landscaping practices. The integration of cutting-edge technologies, including sensors, actuators, and data analysis, empowers this system to provide accurate monitoring and control of irrigation processes by leveraging real-time environmental conditions. The main objective of a smart irrigation system is to optimize water efficiency, minimize expenses, and foster the adoption of sustainable water management methods. This paper conducts a systematic risk assessment by exploring the key components/assets and their functionalities in the smart irrigation system. The crucial role of sensors in gathering data on soil moisture, weather patterns, and plant well-being is emphasized in this system. These sensors enable intelligent decision-making in irrigation scheduling and water distribution, leading to enhanced water efficiency and sustainable water management practices. Actuators enable automated control of irrigation devices, ensuring precise and targeted water delivery to plants. Additionally, the paper addresses the potential threat and vulnerabilities associated with smart irrigation systems. It discusses limitations of the system, such as power constraints and computational capabilities, and calculates the potential security risks. The paper suggests possible risk treatment methods for effective secure system operation. In conclusion, the paper emphasizes the significant benefits of implementing smart irrigation systems, including improved water conservation, increased crop yield, and reduced environmental impact. Additionally, based on the security analysis conducted, the paper recommends the implementation of countermeasures and security approaches to address vulnerabilities and ensure the integrity and reliability of the system. By incorporating these measures, smart irrigation technology can revolutionize water management practices in agriculture, promoting sustainability, resource efficiency, and safeguarding against potential security threats.
Introduction- e - waste – definition - sources of e-waste– hazardous substances in e-waste - effects of e-waste on environment and human health- need for e-waste management– e-waste handling rules - waste minimization techniques for managing e-waste – recycling of e-waste - disposal treatment methods of e- waste – mechanism of extraction of precious metal from leaching solution-global Scenario of E-waste – E-waste in India- case studies.
6th International Conference on Machine Learning & Applications (CMLA 2024)ClaraZara1
6th International Conference on Machine Learning & Applications (CMLA 2024) will provide an excellent international forum for sharing knowledge and results in theory, methodology and applications of on Machine Learning & Applications.
Advanced control scheme of doubly fed induction generator for wind turbine us...IJECEIAES
This paper describes a speed control device for generating electrical energy on an electricity network based on the doubly fed induction generator (DFIG) used for wind power conversion systems. At first, a double-fed induction generator model was constructed. A control law is formulated to govern the flow of energy between the stator of a DFIG and the energy network using three types of controllers: proportional integral (PI), sliding mode controller (SMC) and second order sliding mode controller (SOSMC). Their different results in terms of power reference tracking, reaction to unexpected speed fluctuations, sensitivity to perturbations, and resilience against machine parameter alterations are compared. MATLAB/Simulink was used to conduct the simulations for the preceding study. Multiple simulations have shown very satisfying results, and the investigations demonstrate the efficacy and power-enhancing capabilities of the suggested control system.
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsVictor Morales
K8sGPT is a tool that analyzes and diagnoses Kubernetes clusters. This presentation was used to share the requirements and dependencies to deploy K8sGPT in a local environment.
2. What is AJAX?
• AJAX = Asynchronous JavaScript And XML.
• AJAX is not a programming language.
• AJAX just uses a combination of:
• A browser built-in XMLHttpRequest object (to request data from a web server)
• JavaScript and HTML DOM (to display or use the data)
• AJAX is a misleading name. AJAX applications might use XML to transport data, but it is
equally common to transport data as plain text or JSON text.
• AJAX allows web pages to be updated asynchronously by exchanging data with a web
server behind the scenes. This means that it is possible to update parts of a web page,
without reloading the whole page.
4. AJAX - The XMLHttpRequest Object
• The XMLHttpRequest object can be used to exchange data with a web server behind the scenes. This means that it
is possible to update parts of a web page, without reloading the whole page.
Create an XMLHttpRequest Object
• All modern browsers (Chrome, Firefox, IE7+, Edge, Safari, Opera) have a built-in XMLHttpRequest object.
Syntax:
variable = new XMLHttpRequest();
Example
var xhttp = new XMLHttpRequest();
Access Across Domains
• For security reasons, modern browsers do not allow access across domains.
• This means that both the web page and the XML file it tries to load, must be located on the same server.
• The examples on W3Schools all open XML files located on the W3Schools domain.
• If you want to use the example above on one of your own web pages, the XML files you load must be located on
your own server.
5. Older Browsers (IE5 and IE6)
• Old versions of Internet Explorer (5/6) use an ActiveX object instead of the
XMLHttpRequest object:
variable = new ActiveXObject("Microsoft.XMLHTTP");
• To handle IE5 and IE6, check if the browser supports the XMLHttpRequest object,
or else create an ActiveX object:
Example
if (window.XMLHttpRequest) {
// code for modern browsers
xmlhttp = new XMLHttpRequest();
} else {
// code for old IE browsers
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
6. 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
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
7. XMLHttpRequest Object Properties
Property Description
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")
8. Send a Request To a Server
• To send a request to a server, we use the open() and send() methods of the
XMLHttpRequest object:
xhttp.open("GET", "ajax_info.txt", true);
xhttp.send();
GET or POST?
• GET is simpler and faster than POST, and can be used in most cases.
• However, always use POST requests when:
• A cached file is not an option (update a file or database on the server).
• Sending a large amount of data to the server (POST has no size limitations).
• Sending user input (which can contain unknown characters), POST is more robust
and secure than GET.
9. GET Requests
Example
xhttp.open("GET", "demo_get.asp", true);
xhttp.send();
• In the example above, you may get a cached result. To avoid this, add a unique
ID to the URL:
Example
xhttp.open("GET", "demo_get.asp?t=" + Math.random(), true);
xhttp.send();
• If you want to send information with the GET method, add the information to
the URL:
Example
xhttp.open("GET", "demo_get2.asp?fname=Henry&lname=Ford", true);
xhttp.send();
10. POST Requests
Example
xhttp.open("POST", "demo_post.asp", true);
xhttp.send();
• To POST data like an HTML form, add an HTTP header with setRequestHeader(). Specify the data you want to send
in the send() method:
Example
xhttp.open("POST", "ajax_test.asp", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("fname=Henry&lname=Ford");
Method Description
setRequestHeader(header, value) Adds HTTP headers to the request
header: specifies the header name
value: specifies the header value
The url - A File On a Server
• The url parameter of the open() method, is an address to a file on a server:
xhttp.open("GET", "ajax_test.asp", true);
• The file can be any kind of file, like .txt and .xml, or server scripting files like .asp and .php (which can perform
actions on the server before sending the response back).
11. Asynchronous - True or False?
• Server requests should be sent asynchronously.
• The async parameter of the open() method should be set to true:
xhttp.open("GET", "ajax_test.asp", true);
• By sending asynchronously, the JavaScript does not have to wait for the server response, but can
instead:
• execute other scripts while waiting for server response
• deal with the response after the response is ready
The onreadystatechange Property
• With the XMLHttpRequest object you can define a function to be executed when the request
receives an answer.
• The function is defined in the onreadystatechange property of the XMLHttpResponse object:
Example
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
xhttp.open("GET", "ajax_info.txt", true);
xhttp.send();
12. Synchronous Request
• To execute a synchronous request, change the third parameter in the
open() method to false:
xhttp.open("GET", "ajax_info.txt", false);
• Sometimes async = false are used for quick testing. You will also find
synchronous requests in older JavaScript code.
• Since the code will wait for server completion, there is no need for an
onreadystatechange function:
Example
xhttp.open("GET", "ajax_info.txt", false);
xhttp.send();
document.getElementById("demo").innerHTML = xhttp.responseText;
13. Server Response
The onreadystatechange Property
• The readyState property holds the status of the XMLHttpRequest.
• The onreadystatechange property defines a function to be executed
when the readyState changes.
• The status property and the statusText property holds the status of the
XMLHttpRequest object.
• The onreadystatechange function is called every time the readyState
changes.
• When readyState is 4 and status is 200, the response is ready:
14. function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML =
this.responseText;
}
};
xhttp.open("GET", "ajax_info.txt", true);
xhttp.send();
}
• The onreadystatechange event is triggered four times (1-4), one time
for each change in the readyState.
15. Using a Callback Function
• A callback function is a function passed as a parameter to another function.
• If you have more than one AJAX task in a website, you should create one function for executing the XMLHttpRequest object, and one callback
function for each AJAX task.
• The function call should contain the URL and what function to call when the response is ready.
Example
loadDoc("url-1", myFunction1);
loadDoc("url-2", myFunction2);
function loadDoc(url, cFunction) {
var xhttp;
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
cFunction(this);
}
};
xhttp.open("GET", url, true);
xhttp.send();
}
function myFunction1(xhttp) {
// action goes here
}
function myFunction2(xhttp) {
// action goes here
}