Ajax
muhammadabaloch
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 order to create
faster and more user friendly web pages.
• It is a client side technology.
muhammadabaloch
Purpose of AJAX
• Prevents unnecessary reloading of a page.
• When we submit a form, although most of the page remains the same, whole
page is reloaded from the server.
• This causes very long waiting times and waste of bandwidth.
• AJAX aims at loading only the necessary information, and making only the
necessary changes on the current page without reloading the whole page.
muhammadabaloch
Technologies Used
• AJAX uses:
• Javascript (for altering the page)
• XML (for information exchange)
• PHP or JSP (server side)
muhammadabaloch
Simple Processing
• Ajax (sometimes written AJAX) is a means of using JavaScript to communicate
with a web server without submitting a form or loading a new page.
• AJAX is based on Javascript, and the main functionality is to access the web
server inside the Javascript code.
• We access to the server using special objects; we send data and retrieve data.
muhammadabaloch
The XMLHttpRequest object
• The XMLHttpRequest object is the backbone of every Ajax
method. Each application requires the creation of one of these
objects. So how do we do it?
• Firefox, Safari, Opera, and some other browsers can create one of
these objects simply using the “new” keyword.
<script type="text/javascript">
ajaxRequest = new XMLHttpRequest();
</script>
muhammadabaloch
XMLHttpRequest object properties
We use the readyState to determine when the request has been completed, and then check the status to se if
it executed without an error. (We’ll see how to do this shortly.)
muhammadabaloch
Property Description
readyState An integer from 0. . .4. (0 means the call is uninitialized, 4 means that the call is complete.)
onreadystatechange Determines the function called when the objects readyState changes.
responseText Data returned from the server as a text string (read-only).
responseXML Data returned from the server as an XML document object (read-only).
status HTTP status code returned by the server
statusText HTTP status phrase returned by the server
XMLHttpRequest properties(readyState)
muhammadabaloch
Value Definition
0 Uninitialized
-Object contains no data
1 Loading
-Object is currently loading its data
2 Loaded
-Object has finished loading its data
3 Interactive
-User may interact with the object even though it’s not fully loaded
4 Complete
-Object has finished initializing
XMLHttpRequest properties(status)
• Event Handler
- onreadystatechange
muhammadabaloch
Value Definition
200 Ok
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
500 Internal Server Error
XMLHttpRequest Method
• abort()
• getAllResponseHeaders()
• getResponseHeader( “headername” )
• open(“method” , “url” async );
-open( “GET” , “myfile.php” , true )
• send( content )
• setRequestHeader( “label” , “value” )
muhammadabaloch
Ajax code
<script type="application/javascript">
function formData(){
xhr = undefined ;
if(window.XMLHttpRequest){
// checking browser like chrome , firefox etc......
xhr = new XMLHttpRequest(); // creating object of XMLHttpRequest
}
xhr.onreadystatechange = function(){
// onreadystatechange event with js function which has no name
// but onreadystatechange check readystate value like 0 , 1, .... 4
muhammadabaloch
Ajax code (cont’)
if( xhr.readyState == 4 && xhr.status == 404 ){
// if condition ~ 404 page not found ~ 200 page exist
document.getElementById( "form" ).innerHTML = xhr.responseText ;
// xhr response text inserting in html element
} // end if condition
} // end onreadystatechange
xhr.open("POST" , "form.php" , true) ; // open method
xhr.send( null ); // finaly sending xhr request .....
} // formData()
</script>
<a href="javascript:void(0)" onClick="formData()"> click here </a>
<div id="form"></div>
muhammadabaloch

More Related Content

PPT
PPTX
Learn AJAX at ASIT
PPTX
Ajax Technology
PPTX
Overview of AJAX
Learn AJAX at ASIT
Ajax Technology
Overview of AJAX

What's hot (20)

PDF
Ajax & Reverse Ajax Presenation
PPTX
Introduction to ajax
PPT
2310 b 13
PPTX
Ajax ppt - 32 slides
PPT
PPT
Ajax Patterns : Periodic Refresh & Multi Stage Download
PDF
ITI006En-AJAX
PPT
PPT
Ajax Presentation
PPT
ODP
Ajaxcom
PDF
Introduction to AJAX
PPTX
Ajax and ASP.NET AJAX
TXT
25250716 seminar-on-ajax text
PPTX
Xml and webservice
PDF
Jsp & Ajax
PPTX
ajax - the basics
Ajax & Reverse Ajax Presenation
Introduction to ajax
2310 b 13
Ajax ppt - 32 slides
Ajax Patterns : Periodic Refresh & Multi Stage Download
ITI006En-AJAX
Ajax Presentation
Ajaxcom
Introduction to AJAX
Ajax and ASP.NET AJAX
25250716 seminar-on-ajax text
Xml and webservice
Jsp & Ajax
ajax - the basics
Ad

Similar to Ajax (20)

PPTX
AJAX.pptx
PPT
PPTX
Unit-5.pptx
PPT
Ajax Tuturial
PPT
PPTX
HSHDGDGDHDYDUDUDUDHDHDHSHAHAHSHSBDHDHDHDHDHD
PPT
Ajax tutorial by bally chohan
PPT
Web Programming using Asynchronous JavaX
PPT
PHP - Introduction to PHP AJAX
PPT
PDF
Ajax and xml
PPTX
PPT
Asynchronous JavaScript & XML (AJAX)
PPTX
WEB TECHNOLOGY Unit-5.pptx
PPTX
Web-Engineering-Lec-14 (1 ).pptx
PPTX
Web-Engineering-Lec-14 (1) .pptx
AJAX.pptx
Unit-5.pptx
Ajax Tuturial
HSHDGDGDHDYDUDUDUDHDHDHSHAHAHSHSBDHDHDHDHDHD
Ajax tutorial by bally chohan
Web Programming using Asynchronous JavaX
PHP - Introduction to PHP AJAX
Ajax and xml
Asynchronous JavaScript & XML (AJAX)
WEB TECHNOLOGY Unit-5.pptx
Web-Engineering-Lec-14 (1 ).pptx
Web-Engineering-Lec-14 (1) .pptx
Ad

More from Mudasir Syed (20)

PPT
Error reporting in php
PPT
Cookies in php lecture 2
PPT
Cookies in php lecture 1
PPT
Reporting using FPDF
PPT
Oop in php lecture 2
PPT
Oop in php lecture 2
PPT
Filing system in PHP
PPT
Time manipulation lecture 2
PPT
Time manipulation lecture 1
PPT
Php Mysql
PPT
Adminstrating Through PHPMyAdmin
PPT
Sql select
PPT
PHP mysql Sql
PPT
PHP mysql Mysql joins
PPTX
PHP mysql Introduction database
PPT
PHP mysql Installing my sql 5.1
PPT
PHP mysql Er diagram
PPT
PHP mysql Database normalizatin
PPT
PHP mysql Aggregate functions
PPT
Form validation with built in functions
Error reporting in php
Cookies in php lecture 2
Cookies in php lecture 1
Reporting using FPDF
Oop in php lecture 2
Oop in php lecture 2
Filing system in PHP
Time manipulation lecture 2
Time manipulation lecture 1
Php Mysql
Adminstrating Through PHPMyAdmin
Sql select
PHP mysql Sql
PHP mysql Mysql joins
PHP mysql Introduction database
PHP mysql Installing my sql 5.1
PHP mysql Er diagram
PHP mysql Database normalizatin
PHP mysql Aggregate functions
Form validation with built in functions

Recently uploaded (20)

PPTX
Share_Module_2_Power_conflict_and_negotiation.pptx
PPTX
TNA_Presentation-1-Final(SAVE)) (1).pptx
PDF
Empowerment Technology for Senior High School Guide
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
HVAC Specification 2024 according to central public works department
PDF
advance database management system book.pdf
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PDF
Trump Administration's workforce development strategy
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
Complications of Minimal Access-Surgery.pdf
PDF
My India Quiz Book_20210205121199924.pdf
PDF
Uderstanding digital marketing and marketing stratergie for engaging the digi...
Share_Module_2_Power_conflict_and_negotiation.pptx
TNA_Presentation-1-Final(SAVE)) (1).pptx
Empowerment Technology for Senior High School Guide
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
Chinmaya Tiranga quiz Grand Finale.pdf
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
HVAC Specification 2024 according to central public works department
advance database management system book.pdf
A powerpoint presentation on the Revised K-10 Science Shaping Paper
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
Trump Administration's workforce development strategy
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
Complications of Minimal Access-Surgery.pdf
My India Quiz Book_20210205121199924.pdf
Uderstanding digital marketing and marketing stratergie for engaging the digi...

Ajax

  • 2. 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 order to create faster and more user friendly web pages. • It is a client side technology. muhammadabaloch
  • 3. Purpose of AJAX • Prevents unnecessary reloading of a page. • When we submit a form, although most of the page remains the same, whole page is reloaded from the server. • This causes very long waiting times and waste of bandwidth. • AJAX aims at loading only the necessary information, and making only the necessary changes on the current page without reloading the whole page. muhammadabaloch
  • 4. Technologies Used • AJAX uses: • Javascript (for altering the page) • XML (for information exchange) • PHP or JSP (server side) muhammadabaloch
  • 5. Simple Processing • Ajax (sometimes written AJAX) is a means of using JavaScript to communicate with a web server without submitting a form or loading a new page. • AJAX is based on Javascript, and the main functionality is to access the web server inside the Javascript code. • We access to the server using special objects; we send data and retrieve data. muhammadabaloch
  • 6. The XMLHttpRequest object • The XMLHttpRequest object is the backbone of every Ajax method. Each application requires the creation of one of these objects. So how do we do it? • Firefox, Safari, Opera, and some other browsers can create one of these objects simply using the “new” keyword. <script type="text/javascript"> ajaxRequest = new XMLHttpRequest(); </script> muhammadabaloch
  • 7. XMLHttpRequest object properties We use the readyState to determine when the request has been completed, and then check the status to se if it executed without an error. (We’ll see how to do this shortly.) muhammadabaloch Property Description readyState An integer from 0. . .4. (0 means the call is uninitialized, 4 means that the call is complete.) onreadystatechange Determines the function called when the objects readyState changes. responseText Data returned from the server as a text string (read-only). responseXML Data returned from the server as an XML document object (read-only). status HTTP status code returned by the server statusText HTTP status phrase returned by the server
  • 8. XMLHttpRequest properties(readyState) muhammadabaloch Value Definition 0 Uninitialized -Object contains no data 1 Loading -Object is currently loading its data 2 Loaded -Object has finished loading its data 3 Interactive -User may interact with the object even though it’s not fully loaded 4 Complete -Object has finished initializing
  • 9. XMLHttpRequest properties(status) • Event Handler - onreadystatechange muhammadabaloch Value Definition 200 Ok 400 Bad Request 401 Unauthorized 403 Forbidden 404 Not Found 500 Internal Server Error
  • 10. XMLHttpRequest Method • abort() • getAllResponseHeaders() • getResponseHeader( “headername” ) • open(“method” , “url” async ); -open( “GET” , “myfile.php” , true ) • send( content ) • setRequestHeader( “label” , “value” ) muhammadabaloch
  • 11. Ajax code <script type="application/javascript"> function formData(){ xhr = undefined ; if(window.XMLHttpRequest){ // checking browser like chrome , firefox etc...... xhr = new XMLHttpRequest(); // creating object of XMLHttpRequest } xhr.onreadystatechange = function(){ // onreadystatechange event with js function which has no name // but onreadystatechange check readystate value like 0 , 1, .... 4 muhammadabaloch
  • 12. Ajax code (cont’) if( xhr.readyState == 4 && xhr.status == 404 ){ // if condition ~ 404 page not found ~ 200 page exist document.getElementById( "form" ).innerHTML = xhr.responseText ; // xhr response text inserting in html element } // end if condition } // end onreadystatechange xhr.open("POST" , "form.php" , true) ; // open method xhr.send( null ); // finaly sending xhr request ..... } // formData() </script> <a href="javascript:void(0)" onClick="formData()"> click here </a> <div id="form"></div> muhammadabaloch