SlideShare a Scribd company logo
AJAX

Nibin Manuel

2/12/2014

1
Topics:
• AJAX Overview.
• jQuery's AJAX
related methods.
• Ajax and Forms.
• Ajax Events
2/12/2014

2
What is Ajax?
Asynchronous JavaScript and XML
The technologies involved in an AJAX solution includes:

• JavaScript, to capture interactions with the user
or other browser-related events
• The XMLHttpRequest object, which allows requests to be
made to the server without interrupting other browser tasks
• XML files on the server, or often other similar data formats
such as HTML or JSON
• More JavaScript, to interpret the data from the server and
present it on the page
2/12/2014

3
Why Ajax?
Web
page

Request
Response

Web
page

Web
page

Web
server

Request

Web
page

Response

Ajax Request Model
Traditional Request Model

2/12/2014

4
Why Ajax?

Source: Garrett(2005)
2/12/2014

5
JQuery AJAX Methods:
jQuery.ajax( options )

Load a remote page using an HTTP request.

jQuery.get( url, [data], [callback], [type] )
Load a remote page using an HTTP GET request.

jQuery.getJSON( url, [data], [callback] )
Load JSON data using an HTTP GET request.

jQuery.getScript( url, [callback] )

Loads and executes a JavaScript file using an HTTP GET request.

jQuery.post( url, [data], [callback], [type] )
Load a remote page using an HTTP POST request.

load( url, [data], [callback] )

Load HTML from a remote file and inject it into the DOM.

serialize( )

Serializes a set of input elements into a string of data.

serializeArray( )

Serializes all forms and form elements like the .serialize() method but returns a JSON data structure
for you to work with.
2/12/2014

6
Loading simple data
This is very easy to load any static or dynamic data using JQuery
AJAX. JQuery provides load() method to do the job:
Syntax:

[selector].load( URL, [data], [callback] );
Here is the description of all the parameters:
•

URL: The URL of the server-side resource to which the request is sent

•

data: This optional parameter represents an object whose properties are
serialized into properly encoded parameters to be passed to the request

•

callback: A callback function invoked after the response data has been loaded
into the elements of the matched set. The first parameter passed to this
function is the response text received from the server and second parameter is

the status code.
2/12/2014

7
Getting JSON data
There would be a situation when server would return
JSON string against your request.
JQuery utility function getJSON() parses the returned
JSON string and makes the resulting string available to
the callback function as first parameter to take further
action.

Syntax:
[selector].getJSON( URL, [data], [callback] );

2/12/2014

8
Passing data to the Server:
Many times you collect input from the user and you pass that
input to the server for further processing. JQuery AJAX made it
easy enough to pass collected data to the server using data
parameter of any available Ajax method.
Example:
This example demonstrate how can pass user input to a web
server script which would send the same result back and we
would print it:

2/12/2014

9
jQuery - jQuery.ajax( options ) Method
The jQuery.ajax( options ) method loads a remote page using
an HTTP request.
$.ajax() returns the XMLHttpRequest that it creates. In most
cases you won't need that object to manipulate directly, but it
is available if you need to abort the request manually.
Syntax:
$.ajax( options )
options: A set of key/value pairs that configure the Ajax
request. All options are optional.
Here is the list of option which could be used as key/value
pairs. Except URL, rest of the parameters are optional:
2/12/2014

10
Option
async
beforeSend
complete
contentType
data
dataFilter
dataType
error
global
jsonp
password
processData
success
timeout
type
url
username

Description
A Boolean indicating whether to perform the request asynchronously. The
default value is true.
A callback function that is executed before the request is sent.
A callback function that executes whenever the request finishes.
A string containing a MIME content type to set for the request. The default
value is application/x-www-form-urlencoded.
A map or string that is sent to the server with the request.
A function to be used to handle the raw responsed data of XMLHttpRequest.
This is a pre-filtering function to sanitize the response.
A string defining the type of data expected back from the server (xml, html,
json, or script).
A callback function that is executed if the request fails.
A Boolean indicating whether global AJAX event handlers will be triggered by
this request. The default value is true.
Override the callback function name in a jsonp request.
A password to be used in response to an HTTP access authentication request.
A Boolean indicating whether to convert the submitted data from an object
form into a query-string form. The default value is true.
A callback function that is executed if the request succeeds.
Set a local timeout (in milliseconds) for the request.
A string defining the HTTP method to use for the request (GET or POST). The
default value is GET.
A string containing the URL to which the request is sent.
A username to be used in response to an HTTP access authentication request.
post() Method
The jQuery.post( url, [data], [callback], [type] ) method loads a
page from the server using a POST HTTP request.
The method returns XMLHttpRequest object.
Unlike most jQuery functions, you don’t add get() or post() to a
jQuery selector- in other words, you’d never do something like
this: $(“#maincontent”).get(“result.php”).
Syntax:

$.post( url, [data], [callback], [type] )
2/12/2014

12
Parameters:
•url: A string containing the URL to which the request is sent

•data:: This optional parameter represents key/value pairs or the
return value of the .serialize() function that will be sent to the
server.
•callback:: This optional parameter represents a function to be
executed whenever the data is loaded successfully.
•type:: This optional parameter represents a type of data to be
returned to callback function:
"xml", "html", "script", "json", "jsonp", or "text".
2/12/2014

13
Get() Method
The jQuery.get( url, [data], [callback], [type] ) method
loads data from the server using a GET HTTP request.
The method returns XMLHttpRequest object.
Syntax:
$.get( url, [data], [callback], [type] )

Parameters:
• data:: This optional parameter represents key/value pairs
that will be sent to the server.

2/12/2014

14
jQuery - getScript() Method
The jQuery.getScript( url, [callback] ) method loads and
executes a JavaScript file using an HTTP GET request.

The method returns XMLHttpRequest object.
Syntax:

$.getScript( url, [callback] )
Parameters:
•url: A string containing the URL to which the request is sent
•callback:: This optional parameter represents a function to be
executed whenever the data is loaded successfully.
2/12/2014

15
Jquery - serialize( ) Method
• The serialize( ) method serializes a set of input elements into
a string of data.
Syntax:
$.serialize( )
creates a query string like this:
field_1=something&field2=somethingElse
• sometimes your application would work better if you sent
over an array of objects, instead of just the query string.
This can be done using serializeArray(). creates a structure
like this:
2/12/2014

16
Jquery - serializeArray( ) Method
serializeArray(): It produces an array of objects, instead of a
string and creates a structure like this:
[
{
name : "field_1",
value : "something“
},
{
name : "field_2",
value : "somethingElse“
}
]
2/12/2014

17
JQuery AJAX Events
ajaxComplete( callback )

Attach a function to be executed whenever an AJAX request completes.

ajaxStart( callback )

Attach a function to be executed whenever an AJAX request begins and there is
none already active.

ajaxError( callback )

Attach a function to be executed whenever an AJAX request fails.

ajaxSend( callback )

Attach a function to be executed before an AJAX request is sent.

ajaxStop( callback )

Attach a function to be executed whenever all AJAX requests have ended.

ajaxSuccess( callback )

Attach a function to be executed whenever an AJAX request completes
successfully.
2/12/2014

18
Jquery - ajaxComplete( callback ) Method
The ajaxComplete( callback ) method attaches a function to
be executed whenever an AJAX request completes. This is an
Ajax Event.
Syntax:
$[selector].ajaxComplete( )
Parameters:
• callback: The function to execute. The
XMLHttpRequest and settings used for that request are
passed as arguments to this function.
2/12/2014

19
Jquery - ajaxStart( callback ) Method
The ajaxStart( callback ) method attaches a function to be
executed whenever an AJAX request begins and there is none
already active. This is an Ajax Event.
Syntax:
$[selector].ajaxStart( callback )
Parameters:
• callback: The function to execute.

2/12/2014

20
Jquery - ajaxError( callback ) Method
The ajaxError( callback ) method attaches a function to be
executed whenever an AJAX request fails. This is an Ajax Event.
Syntax:

$[selector].ajaxError( callback )
Parameters:

•callback: The function to execute. The XMLHttpRequest and
settings used for that request are passed as arguments to this
function. A third argument, an exception object, is passed if an
exception occured while processing the request.
2/12/2014

21
Jquery - ajaxSend( callback ) Method
The ajaxSend( callback ) method attaches a function to be
executed whenever an AJAX request is sent. This is an Ajax
Event.
Syntax:

$[selector].ajaxSend( callback )
Parameters:
• callback: The function to execute. The XMLHttpRequest and
settings used for that request are passed as arguments to the
callback.
2/12/2014

22
Jquery - ajaxStop( callback ) Method
The ajaxStop( callback ) method attaches a function to be
executed whenever all AJAX requests have ended. This is an
Ajax Event.
Syntax:
$[selector].ajaxStop( callback )
Parameters:
•callback: The function to execute.

2/12/2014

23
Jquery - ajaxSuccess( callback ) Method
The ajaxSuccess( callback ) method attaches a function to be
executed whenever an AJAX request completes successfully.
This is an Ajax Event.
Syntax:
$[selector].ajaxSuccess( callback )
Parameters:
•callback: The function to execute. The event
object, XMLHttpRequest, and settings used for that request
are passed as arguments to the callback.

2/12/2014

24
Ajax and Forms
• Step 1 - Build the HTML Form
• Step 2 - Begin Adding jQuery
• Step 3 - Write Some Form Validation

• Step 4 - Process our Form Submission with jQuery’s
AJAX Function
• Step 5 - Display a Message Back to the User

2/12/2014

25
Bibliography
• JavaScript & jQuery - David Sawyer McFarland.
• Learning jQuery1.3 - Jonathan Chaffer Karl
Swedberg.
• http://docs.jquery.com
• http://jqfundamentals.com

2/12/2014

26
Ajax

More Related Content

What's hot

Ch06 ado.net fundamentals
Ch06 ado.net fundamentalsCh06 ado.net fundamentals
Ch06 ado.net fundamentalsMadhuri Kavade
 
21servers And Applets
21servers And Applets21servers And Applets
21servers And AppletsAdil Jafri
 
Core Java tutorial at Unit Nexus
Core Java tutorial at Unit NexusCore Java tutorial at Unit Nexus
Core Java tutorial at Unit Nexus
Unit Nexus Pvt. Ltd.
 
Advanced .NET Data Access with Dapper
Advanced .NET Data Access with Dapper Advanced .NET Data Access with Dapper
Advanced .NET Data Access with Dapper
David Paquette
 
Database Connection Pooling With c3p0
Database Connection Pooling With c3p0Database Connection Pooling With c3p0
Database Connection Pooling With c3p0
Kasun Madusanke
 
CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)
Ortus Solutions, Corp
 
ASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And Representation
Randy Connolly
 
What's new in jQuery 1.5
What's new in jQuery 1.5What's new in jQuery 1.5
What's new in jQuery 1.5
Martin Kleppe
 
For Beginers - ADO.Net
For Beginers - ADO.NetFor Beginers - ADO.Net
For Beginers - ADO.Net
Snehal Harawande
 
5\9 SSIS 2008R2_Training - DataFlow Basics
5\9 SSIS 2008R2_Training - DataFlow Basics5\9 SSIS 2008R2_Training - DataFlow Basics
5\9 SSIS 2008R2_Training - DataFlow Basics
Pramod Singla
 
A Practical Approach to Building a Streaming Processing Pipeline for an Onlin...
A Practical Approach to Building a Streaming Processing Pipeline for an Onlin...A Practical Approach to Building a Streaming Processing Pipeline for an Onlin...
A Practical Approach to Building a Streaming Processing Pipeline for an Onlin...
Databricks
 
Data Access Mobile Devices
Data Access Mobile DevicesData Access Mobile Devices
Data Access Mobile Devicesvenkat987
 
Real-time Inverted Search in the Cloud Using Lucene and Storm
Real-time Inverted Search in the Cloud Using Lucene and StormReal-time Inverted Search in the Cloud Using Lucene and Storm
Real-time Inverted Search in the Cloud Using Lucene and Storm
lucenerevolution
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsCarol McDonald
 
Query service in vCloud Director
Query service in vCloud DirectorQuery service in vCloud Director
Query service in vCloud Director
Mayank Goyal
 
Mongo db
Mongo dbMongo db
Mongo db
Athira Mukundan
 
SCWCD : The servlet model : CHAP : 2
SCWCD  : The servlet model : CHAP : 2SCWCD  : The servlet model : CHAP : 2
SCWCD : The servlet model : CHAP : 2
Ben Abdallah Helmi
 
A Deep Dive into Structured Streaming in Apache Spark
A Deep Dive into Structured Streaming in Apache Spark A Deep Dive into Structured Streaming in Apache Spark
A Deep Dive into Structured Streaming in Apache Spark
Anyscale
 

What's hot (20)

Ch06 ado.net fundamentals
Ch06 ado.net fundamentalsCh06 ado.net fundamentals
Ch06 ado.net fundamentals
 
21servers And Applets
21servers And Applets21servers And Applets
21servers And Applets
 
Core Java tutorial at Unit Nexus
Core Java tutorial at Unit NexusCore Java tutorial at Unit Nexus
Core Java tutorial at Unit Nexus
 
Advanced .NET Data Access with Dapper
Advanced .NET Data Access with Dapper Advanced .NET Data Access with Dapper
Advanced .NET Data Access with Dapper
 
Database Connection Pooling With c3p0
Database Connection Pooling With c3p0Database Connection Pooling With c3p0
Database Connection Pooling With c3p0
 
CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)
 
ASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And Representation
 
What's new in jQuery 1.5
What's new in jQuery 1.5What's new in jQuery 1.5
What's new in jQuery 1.5
 
For Beginers - ADO.Net
For Beginers - ADO.NetFor Beginers - ADO.Net
For Beginers - ADO.Net
 
5\9 SSIS 2008R2_Training - DataFlow Basics
5\9 SSIS 2008R2_Training - DataFlow Basics5\9 SSIS 2008R2_Training - DataFlow Basics
5\9 SSIS 2008R2_Training - DataFlow Basics
 
Url programming
Url programmingUrl programming
Url programming
 
A Practical Approach to Building a Streaming Processing Pipeline for an Onlin...
A Practical Approach to Building a Streaming Processing Pipeline for an Onlin...A Practical Approach to Building a Streaming Processing Pipeline for an Onlin...
A Practical Approach to Building a Streaming Processing Pipeline for an Onlin...
 
Data Access Mobile Devices
Data Access Mobile DevicesData Access Mobile Devices
Data Access Mobile Devices
 
Real-time Inverted Search in the Cloud Using Lucene and Storm
Real-time Inverted Search in the Cloud Using Lucene and StormReal-time Inverted Search in the Cloud Using Lucene and Storm
Real-time Inverted Search in the Cloud Using Lucene and Storm
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.js
 
Query service in vCloud Director
Query service in vCloud DirectorQuery service in vCloud Director
Query service in vCloud Director
 
Mongo db
Mongo dbMongo db
Mongo db
 
SCWCD : The servlet model : CHAP : 2
SCWCD  : The servlet model : CHAP : 2SCWCD  : The servlet model : CHAP : 2
SCWCD : The servlet model : CHAP : 2
 
Ajax
AjaxAjax
Ajax
 
A Deep Dive into Structured Streaming in Apache Spark
A Deep Dive into Structured Streaming in Apache Spark A Deep Dive into Structured Streaming in Apache Spark
A Deep Dive into Structured Streaming in Apache Spark
 

Viewers also liked

Ajax basic intro
Ajax basic introAjax basic intro
Ajax basic intro
husnara mohammad
 
Mike Davies - Ajax And Accessibility
Mike Davies - Ajax And AccessibilityMike Davies - Ajax And Accessibility
Mike Davies - Ajax And Accessibility
Christian Heilmann
 
Ajax basics
Ajax basicsAjax basics
Web 2.0 & Ajax Basics
Web 2.0 & Ajax BasicsWeb 2.0 & Ajax Basics
Web 2.0 & Ajax Basics
Abhishek Nagar
 
Html For Beginners 2
Html For Beginners 2Html For Beginners 2
Html For Beginners 2
Sriram Raj
 
Introduction to AJAX
Introduction to AJAXIntroduction to AJAX
Introduction to AJAXjtedesco5
 
Ajax basics
Ajax basicsAjax basics
Ajax basicsVel004
 
Jsp & Ajax
Jsp & AjaxJsp & Ajax
Jsp & Ajax
Ang Chen
 
What is Ajax technology?
What is Ajax technology?What is Ajax technology?
What is Ajax technology?
JavaTpoint.Com
 
Html for Beginners
Html for BeginnersHtml for Beginners
Html for Beginners
Sriram Raj
 
HTML CSS Basics
HTML CSS BasicsHTML CSS Basics
HTML CSS Basics
Mai Moustafa
 

Viewers also liked (12)

Ajax basic intro
Ajax basic introAjax basic intro
Ajax basic intro
 
Mike Davies - Ajax And Accessibility
Mike Davies - Ajax And AccessibilityMike Davies - Ajax And Accessibility
Mike Davies - Ajax And Accessibility
 
Ajax basics
Ajax basicsAjax basics
Ajax basics
 
Web 2.0 & Ajax Basics
Web 2.0 & Ajax BasicsWeb 2.0 & Ajax Basics
Web 2.0 & Ajax Basics
 
Html For Beginners 2
Html For Beginners 2Html For Beginners 2
Html For Beginners 2
 
Introduction to AJAX
Introduction to AJAXIntroduction to AJAX
Introduction to AJAX
 
Ajax basics
Ajax basicsAjax basics
Ajax basics
 
Jsp & Ajax
Jsp & AjaxJsp & Ajax
Jsp & Ajax
 
What is Ajax technology?
What is Ajax technology?What is Ajax technology?
What is Ajax technology?
 
Html for Beginners
Html for BeginnersHtml for Beginners
Html for Beginners
 
Presentation html
Presentation   htmlPresentation   html
Presentation html
 
HTML CSS Basics
HTML CSS BasicsHTML CSS Basics
HTML CSS Basics
 

Similar to Ajax

Unit-5.pptx
Unit-5.pptxUnit-5.pptx
Unit-5.pptx
itzkuu01
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
Adnan Sohail
 
Ajax tutorial by bally chohan
Ajax tutorial by bally chohanAjax tutorial by bally chohan
Ajax tutorial by bally chohan
WebVineet
 
AJAX
AJAXAJAX
AJAX
AJAXAJAX
Ajax and xml
Ajax and xmlAjax and xml
Ajax and xml
sawsan slii
 
Ajax
AjaxAjax
AJAX.pptx
AJAX.pptxAJAX.pptx
AJAX.pptx
Ganesh Chavan
 
jQuery - Chapter 5 - Ajax
jQuery - Chapter 5 -  AjaxjQuery - Chapter 5 -  Ajax
jQuery - Chapter 5 - Ajax
WebStackAcademy
 
Rethinking Syncing at AltConf 2019
Rethinking Syncing at AltConf 2019Rethinking Syncing at AltConf 2019
Rethinking Syncing at AltConf 2019
Joe Keeley
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
Raja V
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
Vibrant Technologies & Computers
 
Ajax
AjaxAjax
jQuery : Talk to server with Ajax
jQuery : Talk to server with AjaxjQuery : Talk to server with Ajax
jQuery : Talk to server with AjaxWildan Maulana
 
Ajax
AjaxAjax

Similar to Ajax (20)

Unit-5.pptx
Unit-5.pptxUnit-5.pptx
Unit-5.pptx
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
 
Ajax tutorial by bally chohan
Ajax tutorial by bally chohanAjax tutorial by bally chohan
Ajax tutorial by bally chohan
 
AJAX
AJAXAJAX
AJAX
 
AJAX
AJAXAJAX
AJAX
 
Ajax
AjaxAjax
Ajax
 
Ajax and xml
Ajax and xmlAjax and xml
Ajax and xml
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
AJAX.pptx
AJAX.pptxAJAX.pptx
AJAX.pptx
 
jQuery - Chapter 5 - Ajax
jQuery - Chapter 5 -  AjaxjQuery - Chapter 5 -  Ajax
jQuery - Chapter 5 - Ajax
 
Ajax Tuturial
Ajax TuturialAjax Tuturial
Ajax Tuturial
 
Rethinking Syncing at AltConf 2019
Rethinking Syncing at AltConf 2019Rethinking Syncing at AltConf 2019
Rethinking Syncing at AltConf 2019
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
jQuery : Talk to server with Ajax
jQuery : Talk to server with AjaxjQuery : Talk to server with Ajax
jQuery : Talk to server with Ajax
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 

Recently uploaded

CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 

Recently uploaded (20)

CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 

Ajax

  • 2. Topics: • AJAX Overview. • jQuery's AJAX related methods. • Ajax and Forms. • Ajax Events 2/12/2014 2
  • 3. What is Ajax? Asynchronous JavaScript and XML The technologies involved in an AJAX solution includes: • JavaScript, to capture interactions with the user or other browser-related events • The XMLHttpRequest object, which allows requests to be made to the server without interrupting other browser tasks • XML files on the server, or often other similar data formats such as HTML or JSON • More JavaScript, to interpret the data from the server and present it on the page 2/12/2014 3
  • 6. JQuery AJAX Methods: jQuery.ajax( options ) Load a remote page using an HTTP request. jQuery.get( url, [data], [callback], [type] ) Load a remote page using an HTTP GET request. jQuery.getJSON( url, [data], [callback] ) Load JSON data using an HTTP GET request. jQuery.getScript( url, [callback] ) Loads and executes a JavaScript file using an HTTP GET request. jQuery.post( url, [data], [callback], [type] ) Load a remote page using an HTTP POST request. load( url, [data], [callback] ) Load HTML from a remote file and inject it into the DOM. serialize( ) Serializes a set of input elements into a string of data. serializeArray( ) Serializes all forms and form elements like the .serialize() method but returns a JSON data structure for you to work with. 2/12/2014 6
  • 7. Loading simple data This is very easy to load any static or dynamic data using JQuery AJAX. JQuery provides load() method to do the job: Syntax: [selector].load( URL, [data], [callback] ); Here is the description of all the parameters: • URL: The URL of the server-side resource to which the request is sent • data: This optional parameter represents an object whose properties are serialized into properly encoded parameters to be passed to the request • callback: A callback function invoked after the response data has been loaded into the elements of the matched set. The first parameter passed to this function is the response text received from the server and second parameter is the status code. 2/12/2014 7
  • 8. Getting JSON data There would be a situation when server would return JSON string against your request. JQuery utility function getJSON() parses the returned JSON string and makes the resulting string available to the callback function as first parameter to take further action. Syntax: [selector].getJSON( URL, [data], [callback] ); 2/12/2014 8
  • 9. Passing data to the Server: Many times you collect input from the user and you pass that input to the server for further processing. JQuery AJAX made it easy enough to pass collected data to the server using data parameter of any available Ajax method. Example: This example demonstrate how can pass user input to a web server script which would send the same result back and we would print it: 2/12/2014 9
  • 10. jQuery - jQuery.ajax( options ) Method The jQuery.ajax( options ) method loads a remote page using an HTTP request. $.ajax() returns the XMLHttpRequest that it creates. In most cases you won't need that object to manipulate directly, but it is available if you need to abort the request manually. Syntax: $.ajax( options ) options: A set of key/value pairs that configure the Ajax request. All options are optional. Here is the list of option which could be used as key/value pairs. Except URL, rest of the parameters are optional: 2/12/2014 10
  • 11. Option async beforeSend complete contentType data dataFilter dataType error global jsonp password processData success timeout type url username Description A Boolean indicating whether to perform the request asynchronously. The default value is true. A callback function that is executed before the request is sent. A callback function that executes whenever the request finishes. A string containing a MIME content type to set for the request. The default value is application/x-www-form-urlencoded. A map or string that is sent to the server with the request. A function to be used to handle the raw responsed data of XMLHttpRequest. This is a pre-filtering function to sanitize the response. A string defining the type of data expected back from the server (xml, html, json, or script). A callback function that is executed if the request fails. A Boolean indicating whether global AJAX event handlers will be triggered by this request. The default value is true. Override the callback function name in a jsonp request. A password to be used in response to an HTTP access authentication request. A Boolean indicating whether to convert the submitted data from an object form into a query-string form. The default value is true. A callback function that is executed if the request succeeds. Set a local timeout (in milliseconds) for the request. A string defining the HTTP method to use for the request (GET or POST). The default value is GET. A string containing the URL to which the request is sent. A username to be used in response to an HTTP access authentication request.
  • 12. post() Method The jQuery.post( url, [data], [callback], [type] ) method loads a page from the server using a POST HTTP request. The method returns XMLHttpRequest object. Unlike most jQuery functions, you don’t add get() or post() to a jQuery selector- in other words, you’d never do something like this: $(“#maincontent”).get(“result.php”). Syntax: $.post( url, [data], [callback], [type] ) 2/12/2014 12
  • 13. Parameters: •url: A string containing the URL to which the request is sent •data:: This optional parameter represents key/value pairs or the return value of the .serialize() function that will be sent to the server. •callback:: This optional parameter represents a function to be executed whenever the data is loaded successfully. •type:: This optional parameter represents a type of data to be returned to callback function: "xml", "html", "script", "json", "jsonp", or "text". 2/12/2014 13
  • 14. Get() Method The jQuery.get( url, [data], [callback], [type] ) method loads data from the server using a GET HTTP request. The method returns XMLHttpRequest object. Syntax: $.get( url, [data], [callback], [type] ) Parameters: • data:: This optional parameter represents key/value pairs that will be sent to the server. 2/12/2014 14
  • 15. jQuery - getScript() Method The jQuery.getScript( url, [callback] ) method loads and executes a JavaScript file using an HTTP GET request. The method returns XMLHttpRequest object. Syntax: $.getScript( url, [callback] ) Parameters: •url: A string containing the URL to which the request is sent •callback:: This optional parameter represents a function to be executed whenever the data is loaded successfully. 2/12/2014 15
  • 16. Jquery - serialize( ) Method • The serialize( ) method serializes a set of input elements into a string of data. Syntax: $.serialize( ) creates a query string like this: field_1=something&field2=somethingElse • sometimes your application would work better if you sent over an array of objects, instead of just the query string. This can be done using serializeArray(). creates a structure like this: 2/12/2014 16
  • 17. Jquery - serializeArray( ) Method serializeArray(): It produces an array of objects, instead of a string and creates a structure like this: [ { name : "field_1", value : "something“ }, { name : "field_2", value : "somethingElse“ } ] 2/12/2014 17
  • 18. JQuery AJAX Events ajaxComplete( callback ) Attach a function to be executed whenever an AJAX request completes. ajaxStart( callback ) Attach a function to be executed whenever an AJAX request begins and there is none already active. ajaxError( callback ) Attach a function to be executed whenever an AJAX request fails. ajaxSend( callback ) Attach a function to be executed before an AJAX request is sent. ajaxStop( callback ) Attach a function to be executed whenever all AJAX requests have ended. ajaxSuccess( callback ) Attach a function to be executed whenever an AJAX request completes successfully. 2/12/2014 18
  • 19. Jquery - ajaxComplete( callback ) Method The ajaxComplete( callback ) method attaches a function to be executed whenever an AJAX request completes. This is an Ajax Event. Syntax: $[selector].ajaxComplete( ) Parameters: • callback: The function to execute. The XMLHttpRequest and settings used for that request are passed as arguments to this function. 2/12/2014 19
  • 20. Jquery - ajaxStart( callback ) Method The ajaxStart( callback ) method attaches a function to be executed whenever an AJAX request begins and there is none already active. This is an Ajax Event. Syntax: $[selector].ajaxStart( callback ) Parameters: • callback: The function to execute. 2/12/2014 20
  • 21. Jquery - ajaxError( callback ) Method The ajaxError( callback ) method attaches a function to be executed whenever an AJAX request fails. This is an Ajax Event. Syntax: $[selector].ajaxError( callback ) Parameters: •callback: The function to execute. The XMLHttpRequest and settings used for that request are passed as arguments to this function. A third argument, an exception object, is passed if an exception occured while processing the request. 2/12/2014 21
  • 22. Jquery - ajaxSend( callback ) Method The ajaxSend( callback ) method attaches a function to be executed whenever an AJAX request is sent. This is an Ajax Event. Syntax: $[selector].ajaxSend( callback ) Parameters: • callback: The function to execute. The XMLHttpRequest and settings used for that request are passed as arguments to the callback. 2/12/2014 22
  • 23. Jquery - ajaxStop( callback ) Method The ajaxStop( callback ) method attaches a function to be executed whenever all AJAX requests have ended. This is an Ajax Event. Syntax: $[selector].ajaxStop( callback ) Parameters: •callback: The function to execute. 2/12/2014 23
  • 24. Jquery - ajaxSuccess( callback ) Method The ajaxSuccess( callback ) method attaches a function to be executed whenever an AJAX request completes successfully. This is an Ajax Event. Syntax: $[selector].ajaxSuccess( callback ) Parameters: •callback: The function to execute. The event object, XMLHttpRequest, and settings used for that request are passed as arguments to the callback. 2/12/2014 24
  • 25. Ajax and Forms • Step 1 - Build the HTML Form • Step 2 - Begin Adding jQuery • Step 3 - Write Some Form Validation • Step 4 - Process our Form Submission with jQuery’s AJAX Function • Step 5 - Display a Message Back to the User 2/12/2014 25
  • 26. Bibliography • JavaScript & jQuery - David Sawyer McFarland. • Learning jQuery1.3 - Jonathan Chaffer Karl Swedberg. • http://docs.jquery.com • http://jqfundamentals.com 2/12/2014 26

Editor's Notes

  1. . URL:It could be a CGI, ASP, JSP, or PHP script which generates data dynamically or out of a database..DATA:. If specified, the request is made using the POST method. If omitted, the GET method is used.
  2. Reduce some options… mention only frequently used ones…
  3. Mention when to use get and when post
  4. All these events are global…
  5. Example already done inseriallization…