Top Banner
AJAX Asynchronous JavaScript and XML Ahmed farag mostafa
12
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Ajax

AJAX Asynchronous JavaScript and XML

Ahmed farag mostafa

Page 2: Ajax

What is Ajax ?• an acronym for Asynchronous JavaScript and XML is a group of

interrelated web development techniques used on the client-side to create asynchronous web applications. With Ajax, web applications can send data to, and retrieve data from, a server asynchronously (in the background) without interfering with the display and behavior of the existing page. Data is usually retrieved using the XMLHttpRequest object. Despite the name, the use of XML is not needed (JSON is often used instead), and the requests do not need to be asynchronous.

• Ajax is not a single technology, but a group of technologies. HTML and CSS can be used in combination to mark up and style information. The DOM is accessed with JavaScript to dynamically display, and to allow the user to interact with the information presented. JavaScript and the XMLHttpRequest object provide a method for exchanging data asynchronously between browser and server to avoid full page reloads.

Page 3: Ajax

Technologies

• HTML (or XHTML) and CSS for presentation• The Document Object Model (DOM) for

dynamic display of and interaction with data• XML for the interchange of data.• The XMLHttpRequest object for asynchronous

communication• JavaScript to bring these technologies

together

Page 4: Ajax

Examples of applications using AJAX:

• Google Maps, Gmail, Youtube, and Facebook tabs.

Page 5: Ajax

How AJAX Works

Page 6: Ajax

AJAX app and classic web

Page 7: Ajax

AJAX app and classic web

Page 8: Ajax

Ajax

• create The XMLHttpRequest Object variable=new XMLHttpRequest();• Send a Request To a Server - get request xmlhttp.open("GET","demo_get2.asp?

fname=ahmed&lname=farag",true);xmlhttp.send();

- post request xmlhttp.open("POST","demo_post.asp",true); xmlhttp.send("fname=ahmed&lname=farag");

Page 9: Ajax

• Server Responsedocument.getElementById("myDiv").innerHTML=xmlhttp.responseText;

Page 10: Ajax

The onreadystatechange Event• xmlhttp.onreadystatechange=function()

{ if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } }

Page 11: Ajax

Questions?

Page 12: Ajax

Thanks ^_^