AJAX محمد احمدی نیا 2 Of 27 What is AJAX?  AJAX = Asynchronous JavaScript and XML.  AJAX is not a new programming language, but.

Slides:



Advertisements
Similar presentations
AJAX asynchronous server-client communication. Test.
Advertisements

Using AJAX Galip Aydin, Ahmet Sayar, and Marlon Pierce Community Grids Lab Indiana University.
PHP with XML & AJAX XML: Extensible Markup Language AJAX: Asynchronous JavaScript and XML.
Introduction to AJAX AJAX Keywords: JavaScript and XML
Ajax (Asynchronous JavaScript and XML). AJAX  Enable asynchronous communication between a web client and a server.  A client is not blocked when an.
Ajax Basics The XMLHttpRequest Object. Ajax is…. Ajax is not…. Ajax is not a programming language. Ajax is not a programming language. Ajax is a methodology.
PHP and AJAX ISYS 475. AJAX Asynchronous JavaScript and XML: – JavaScript, Document Object Model, Cascade Style Sheet, XML, server-side script such as.Net,
Lecture 12 – AJAX SFDV3011 – Advanced Web Development Reference: 1.
Ajax - Part II Communicating with the Server. Learning Objectives By the end of this lecture, you should be able to: – Describe the overview of steps.
JavaScript, Fourth Edition Chapter 12 Updating Web Pages with AJAX.
AJAX and Java ISYS 350. AJAX Asynchronous JavaScript and XML: – Related technologies: JavaScript, Document Object Model, XML, server-side script such.
06/10/2015AJAX 1. 2 Introduction All material from AJAX – what is it? Traditional web pages and operation Examples of AJAX use Creating.
Random Logic l Forum.NET l AJAX Behind the buzz word Forum.NET ● January 23, 2006.
Ajax In Action The Journey into Web2.0 Presented by Eric Pascarello.
Lecture 9: AJAX, Javascript review..  AJAX  Synchronous vs. asynchronous browsing.  Refreshing only “part of a page” from a URL.  Frameworks: Prototype,
Ajax XMod for Dummies Building DNN Ajax Modules Without Programming Dave McMullen SoCal DNN Users Group 2/7/07 –
Asynchronous Javascript And XML AJAX : an introduction UFCEUS-20-2 : Web Programming.
AJAX stands for Asynchronous JavaScript And XML. AJAX is a type of programming made popular in 2005 by Google (with Google Suggest). AJAX is not a new.
Web Technology Introduction AJAXAJAX. AJAX Outline  What is AJAX?  Benefits  Real world examples  How it works  Code review  Samples.
School of Computing and Information Systems CS 371 Web Application Programming AJAX.
CISC 3140 (CIS 20.2) Design & Implementation of Software Application II Instructor : M. Meyer Address: Course Page:
AJAX Asynchronous JavaScript & XML A short introduction.
SYST Web Technologies SYST Web Technologies AJAX.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
 AJAX – Asynchronous JavaScript and XML  Ajax is used to develop fast dynamic web applications  Allows web pages to be updated asynchronously by transferring.
AJAX Asynchronous JavaScript and XML 1. AJAX Outline What is AJAX? Benefits Real world examples How it works 2.
JQuery and AJAX WEB Technologies : PHP Programming Language.
CHAPTER 13 COMMUNICATING WITH AJAX. LEARNING OBJECTIVES AJAX, which stands for Asynchronous JavaScript and XMLprovides a way for a browser to send and.
CHAPTER 8 AJAX & JSON WHAT IS AJAX? Ajax lets you…
AJAX and REST. Slide 2 What is AJAX? It’s an acronym for Asynchronous JavaScript and XML Although requests need not be asynchronous It’s not really a.
AJAX AJAX Asynchronous JavaScript and XML --- MADHAVI
What is AJAX ? Asynchronous Javascript and XML. Not a stand-alone language or technology. It is a technique that combines a set of known technologies in.
AJAX – Asynchronous JavaScript And XML By Kranthi Kiran Nuthi CIS 764 Kansas State University.
INNOV-2: Build a Better Web Interface Using AJAX Chris Morgan Pandora Software Systems
Web Technology (NCS-504) Prepared By Mr. Abhishek Kesharwani Assistant Professor,UCER Naini,Allahabad.
 AJAX technology  Rich User Experience  Characteristics  Real live examples  JavaScript and AJAX  Web application workflow model – synchronous vs.
AJAX CS456 Fall Examples Where is AJAX used? Why do we care?
1 AJAX. AJAX – Whatzit? Asynchronous (content loading)‏ Javascript (logic & control)‏ And XML (request handling)‏
JavaScript, Sixth Edition Chapter 11 Updating Web Pages with Ajax.
JavaScript and Ajax Week 10 Web site:
NCCUCS 軟體工程概論 Lecture 5: Ajax, Mashups April 29, 2014.
AJAX. Objectives Understand and apply AJAX Using AJAX in DOJO library.
Ajax SUBMITTED BY NITIN RAMANI C.S.E 3 rd Y 5 th S R.N CS SUBMITTED TO PRO. PUSHPARAJ PATEL SIR.
Introduction to AJAX Pat Morin COMP Outline What is AJAX? – History – Uses – Pros and Cons An XML HTTP Transaction – Creating an XMLHTTPRequest.
What is AJAX ? Asynchronous Javascript and XML.
JavaScript and Ajax (Ajax Tutorial)
CSE 154 Lecture 11: AJAx.
Understanding XMLHttpRequest
Not a Language but a series of techniques
AJAX AJAX = Asynchronous JavaScript and XML.
CS 371 Web Application Programming
XMLHttp Object.
AJAX.
Web System & Technology
AJAX (Asynchronous JavaScript and XML.)
CSE 154 Lecture 11: AJAx.
AJAX and JSP ISYS 350.
CSE 154 Lecture 22: AJAX.
AJAX Robin Burke ECT 360.
JavaScript & AJAX.
ISC440: Web Programming 2 AJAX
JavaScript & jQuery AJAX.
AJAX CS-422 Dick Steflik.
Web Technology Even Sem 2015
Advanced Concepts and AJAX
AJAX and JSP ISYS 350.
PHP and JSON Topics Review JSON.
What is AJAX? AJAX is a developer's dream, because you can:
Communicating with the Server
Software Engineering for Internet Applications
Presentation transcript:

AJAX محمد احمدی نیا

2 Of 27 What is AJAX?  AJAX = Asynchronous JavaScript and XML.  AJAX is not a new programming language, but a new way to use existing standards.  AJAX is the art of exchanging data with a server, and update parts of a web page - without reloading the whole page.  Examples of applications using AJAX: Google Suggest,Google Maps, Gmail, Youtube, and Facebook tabs. زبانهای برنامه سازی وب

3 Of 27 What is AJAX?  AJAX is based on internet standards, and uses a combination of:  XMLHttpRequest object (to exchange data asynchronously with a server)  JavaScript/DOM (to display/interact with the information)  CSS (to style the data)  XML (often used as the format for transferring data) زبانهای برنامه سازی وب

4 Of 27 How AJAX Works زبانهای برنامه سازی وب

5 Of 27 AJAX Example زبانهای برنامه سازی وب Let AJAX change this text Change Content function loadXMLDoc() {.... AJAX script goes here... }

6 Of 27 XMLHttpRequest Object  The keystone of AJAX is the XMLHttpRequest object.  The XMLHttpRequest object is used to exchange data with a server behind the scenes.  All modern browsers support the XMLHttpRequest object (IE5 and IE6 use an ActiveXObject). زبانهای برنامه سازی وب

7 Of 27 XMLHttpRequest Object  Create an XMLHttpRequest Object  All modern browsers (IE7+, Firefox, Chrome, Safari, and Opera) have a built-in XMLHttpRequest object.  variable=new XMLHttpRequest();  Old versions of Internet Explorer (IE5 and IE6) uses an ActiveX Object:  variable=new ActiveXObject("Microsoft.XMLHTTP"); زبانهای برنامه سازی وب

8 Of 27 XMLHttpRequest Object زبانهای برنامه سازی وب var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }

9 Of 27 Send Request To Server  To send a request to a server, we use the open() and send() methods of the XMLHttpRequest object: زبانهای برنامه سازی وب MethodDescription open(method,url,async) method: the type of request: GET or POST url: the location of the file on the server async: true (asynchronous) or false (synchronous) send(string)Sends the request off to the server. string: Only used for POST requests xmlhttp.open("GET","ajax_info.txt",true); xmlhttp.send();

10 Of 27 GET Requests  GET is simpler and faster than POST, and can be used in most cases.  add the information to the URL for sending زبانهای برنامه سازی وب xmlhttp.open("GET","demo_get.php? fname=Henry “,true); xmlhttp.send();

11 Of 27 POST Requests  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  Sending user input (which can contain unknown characters), POST is more robust and secure than GET زبانهای برنامه سازی وب

12 Of 27 POST Requests  To POST data like an HTML form, add an HTTP header with setRequestHeader(). Specify the data you want to send in the send() method:  setRequestHeader(header,value) header: specifies the header name value: specifies the header value زبانهای برنامه سازی وب xmlhttp.open("POST","ajax_test.asp",true); xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xmlhttp.send("fname=Henry&lname=Ford");

13 Of 27 Asynchronous - False  JavaScript will NOT continue to execute, until the server response is ready. If the server is busy or slow, the application will hang or stop.  Using async=false is not recommended, but for a few small requests this can be ok. زبانهای برنامه سازی وب xmlhttp.open("GET","ajax_info.txt",false); xmlhttp.send(); document.getElementById("myDiv").innerHTML=xmlhttp.responseText;

14 Of 27 Asynchronous – True  AJAX stands for Asynchronous JavaScript and XML  When using async=true, specify a function to execute when the response is ready in the onreadystatechange event  execute other scripts while waiting for server response زبانهای برنامه سازی وب xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","ajax_info.txt",true); xmlhttp.send();

15 Of 27 AJAX - Server Response  To get the response from a server, use the responseText or responseXML property of the XMLHttpRequest object.  The responseText Property زبانهای برنامه سازی وب PropertyDescription responseTextget the response data as a string responseXMLget the response data as XML data document.getElementById("myDiv").innerHTML=xmlhttp.responseText;

16 Of 27 AJAX – onreadystatechange  The onreadystatechange event is triggered every time the readyState changes.  The readyState property holds the status of the XMLHttpRequest. زبانهای برنامه سازی وب

17 Of 27 AJAX – onreadystatechange  Three important properties of the XMLHttpRequest object: زبانهای برنامه سازی وب PropertyDescription onreadystatechange Stores a function (or the name of a function) to be called automatically each time the readyState property changes readyState Holds the status of the XMLHttpRequest. Changes from 0 to 4: 0: request not initialized 1: server connection established 2: request received 3: processing request 4: request finished and response is ready status 200: "OK" 404: Page not found

18 Of 27 AJAX – onreadystatechange  In the onreadystatechange event, we specify what will happen when the server response is ready to be processed.  When readyState is 4 and status is 200, the response is ready: زبانهای برنامه سازی وب xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } }

19 Of 27 AJAX PHP Example  The following example will demonstrate how a web page can communicate with a web server while a user type characters in an input field: زبانهای برنامه سازی وب

20 Of 27 AJAX PHP Example  When a user types a character in the input field above, the function "showHint()" is executed. The function is triggered by the "onkeyup" event: زبانهای برنامه سازی وب Start typing a name in the input field below: First name: Suggestions:

21 Of 27 AJAX PHP Example زبانهای برنامه سازی وب function showHint(str) { var xmlhttp; if (str.length==0) { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","gethint.php?q="+str,true); xmlhttp.send(); }

22 Of 27 AJAX PHP Example  The PHP File  The source code in "gethint.php" checks an array of names, and returns the corresponding name(s) to the browser: زبانهای برنامه سازی وب <?php // Fill up array with names $a[]="Anna"; $a[]="Brittany"; $a[]="Cinderella";.. $a[]="Ellen"; $a[]="Wenche"; $a[]="Vicky"; //get the q parameter from URL $q=$_GET["q"]; …

23 Of 27 زبانهای برنامه سازی وب... //lookup all hints from array if length of q>0 if (strlen($q) > 0) { $hint=""; for($i=0; $i

24 Of 27 AJAX Database Example  The following example will demonstrate how a web page can fetch information from a database with AJAX: زبانهای برنامه سازی وب

25 Of 27 The HTML Page زبانهای برنامه سازی وب function showUser(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getuser.php?q="+str,true); xmlhttp.send(); } …

26 Of 27 The HTML Page زبانهای برنامه سازی وب … Select a person: Peter Griffin Lois Griffin Glenn Quagmire Joseph Swanson Person info will be listed here.

27 Of 27 The PHP File( getuser.php ) زبانهای برنامه سازی وب <?php $q=$_GET["q"]; $con = mysql_connect('localhost', 'peter', 'abc123'); mysql_select_db("ajax_demo", $con); $sql="SELECT * FROM user WHERE id = '".$q."'"; $result = mysql_query($sql); echo " Firstname Lastname Hometown Job "; while($row = mysql_fetch_array($result)) { echo " "; echo " ". $row['FirstName']. " "; echo " ". $row['LastName']. " "; echo " ". $row['Hometown']. " "; echo " ". $row['Job']. " "; echo " "; } echo " "; ?>