SlideShare a Scribd company logo
Web Technologies – CS 382
Shehzad Aslam
Lecture 7
2 Hr
 AJAX introduction
 Where t use AJAX
 Combining AJAX with JSON
 Review of JavaScript Object & JSON
 AJAX with simple JavaScript
 Asynchronous JavaScript and XML
 Technique for creating better, faster, and more interactive web applications
 Uses XHTML for content with DOM & JavaScript to display dynamic content
 Traditional Page is synchronous
 You submit form, hit enter and wait to be redirected to another page
 AJAX is Asynchronous
 Will make a background request and update the page, while you are doing other things in the
page
 Where to use
 Scroll a page, some of the contents will load after scroll (just like Google image search)
 Do chat, after certain time pull new contents
 Notifications, after certain time pull new notification
 Tell that you are active; after certain time ping server with some data
 When doing search, show hits; or provide some data, remaining will be filled
Use where you do not want to reload page
 Runs on browser not Server
 Not a language, can say a technique or Library
 Basically Designed for XML Response
 But can use any data format (plain text, XML, CSV, JSON, HTML etc)
 Behind the scene, HTTP request is sent
 Powerful use is in searching & forms submission, chat, notifications etc
 Real Examples
 Comments pull on youtube
 Search hints in Google or on some site
 Like option in Facebook
 Next posts pull on Facebook
 Cricket score updates
 … and much more
User interface
Browser
Database
Web server
http request
HTML+CSS Data
User interface
Browser
Database
Web server
http request
XML Data
AJAX Engine
Javascript call
HTML CSS data
Classic web app model AJAX web app model
 Create XHR (XML HTTP Request) Object
 Create a function that will be called when request status change
 It will be a callback function
 Use the data, modify the DOM or what ever you want
 Set options
 where to fetch/send data
 what is the method
 Want Asynchronous or not
 What is HTTP authentication username
 What is HTTP authentication password
 Initiate the connection
var xhr = new XMLHttpRequest(); //object
//callback function
xhr.onreadystatechange = function () {
//check ready state
//check server response code, based on that use data or show error
};
//set request parameters
xhr.open(method, url, [asyn/synch, username, pwd]);
//e.g. xhr.open(“GET”, “http://uet.edy.pk”, true);
//call it on some event
xhr.send();
 abort()
 Cancel current request
 getAllResponseHeaders()
 Get all headers as string
 getResponseHeader(headerName)
 Get all specific headers
 open(method, url, async, username, pwd)
 Specify options
 PUT, DELETE may not possible
 send(contents)
 Sent the request
 setRequestHeader(header, value)
 Add header to be sent to server
 status
 Response status code e.g 200, 404 etc
 statusText
 Response status text e.g. OK, Not Found etc
 readyState
 Information about the current request object (it is a number 0-4)
 onreadystatechange
 An event handler that is fired at every state change
 responseText
 Response as a string
 responseXML
 Response as XML
 readyState property defines current state of XMLHttpRequest object
State Description
0 Request is not initialized
- Created object but not called open yet
1 Request has been setup
- after open has been called but sent not called yet (connected to server)
2 Request has been sent
- After send has been called
3 Request is in process
- browser established a communication but before server completed
response
4 Request has been completed
- request completed, all the response received, data ready
 AJAX not supported by Old browsers
 All modern browsers (Chrome, IE7+, Firefox, Safari, and Opera)
have a built-in XMLHttpRequest object
 Variable = new XMLHttpRequest();
 Old versions of Internet Explorer (IE5 and IE6) use an ActiveX
Object
 variable = new ActiveXObject("Microsoft.XMLHTTP");
var xhttp;
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
var counting= [1,2,3,4];
Will be
[
1,
2,
3,
4
]
var name = [“Ali”, “Umer”];
Will be
[
“Ali”,
“Umer”
]
Java
Script
Object
Notation
var objectname = {
property: value,
property:value
};
Will be
{
“property”:value,
“property”:value,
}
var fish= {
name: “tuna”,
weight:150,
color: “black & gray”
};
?
{
“name”: “tuna”,
“weight”:150,
“color”: “black & gray”
}
Just like so mixed objects
This data could be in new file with
json extension
 Currently we are fetching static contents
 hold until we get our hands on PHP
 You are provided a folder
 Place it in www dir of WAMP
 Create a copy of sample page
 Create a button, define onclick event and do following
 Fetch lect7/data/foods/fruits.json and display using AJAX
 List the fruits
 Create a copy of sample page
 Create a button, define onclick event and do following
 Fetch lect7/data/animals/birds_antarctica.json and display using AJAX
 Family as h2 and members are as unordered list
 Problem
 JSON not turning to object
 jsonObject = JSON.parse(jsonString);
 jQuery.parseJSON( jsonString );
 Create a copy of sample page
 Create a button, define onclick event and do following
 Fetch lec7/data/story.txt and display in a div using AJAX
 Do same for to get lec7/data/story.html and display in new div
 Create new div & do following
 Create a button, define onclick event and do following
 Fetch lec7/data/story.json and display in a div using AJAX
 Title in h1, author in h3, description in italic & story text simple in each line
 Fetch lect7/data/colors/web_colors.json
 Show it in table having one column
 and each row background is hex color given & contents are color name
 Fetch lect7/data/colors/palettes.json
 Show it in table having four column
 and each cell background is hex color given & contents are color code
 Fetch lect7/data/foods/vegetable_cooking_times.json
 Show detail
 Represent RCET, UET, KSK in JSON with following details. Use AJAX to get data
and display on the page
 Departments (array)
 Each department having name, hod name, faculty list (each faculty name, qualification),
no of students in each session
 Cafeteria (array) with list of food items each item having category, served
weight and price
 Playgrounds (array) with description, area
 Hostels (array) with name, warden, rooms (array) with each room resident
name
 Represent your time table in JSON
 Use AJAX to show it just like time table
 * Separate the data that you were changing in the last assignment
 Create some json files having some data in same format, name of file is vourcherno
 When you change the voucher no use AJAX to get data related to that voucherno & show
 Is there a batter way to create HTML with JavaScript
 Yes! But We used string concatenation
 See Handlebars.js
 Practice with given JSON files

More Related Content

What's hot

AJAX
AJAXAJAX
Google cloud datastore driver for Google Apps Script DB abstraction
Google cloud datastore driver for Google Apps Script DB abstractionGoogle cloud datastore driver for Google Apps Script DB abstraction
Google cloud datastore driver for Google Apps Script DB abstraction
Bruce McPherson
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
Vibrant Technologies & Computers
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
Nir Elbaz
 
Ajax
AjaxAjax
Get docs from sp doc library
Get docs from sp doc libraryGet docs from sp doc library
Get docs from sp doc library
Sudip Sengupta
 
Xml And JSON Java
Xml And JSON JavaXml And JSON Java
Xml And JSON Java
Henry Addo
 
Web Development Course - AJAX & JSON by RSOLUTIONS
Web Development Course - AJAX & JSON by RSOLUTIONSWeb Development Course - AJAX & JSON by RSOLUTIONS
Web Development Course - AJAX & JSON by RSOLUTIONS
RSolutions
 
Ajax and PHP
Ajax and PHPAjax and PHP
Ajax and PHP
John Coggeshall
 
Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access
Rebecca Grenier
 
Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012
sullis
 
Ajax Introduction
Ajax IntroductionAjax Introduction
Ajax Introduction
Oliver Cai
 
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
Marco Gralike
 
Ajax xml json
Ajax xml jsonAjax xml json
Ajax xml json
Andrii Siusko
 
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
tdc-globalcode
 
Palestra Java + NoSQL = Iniciativa JNoSQL no TDC Florianópolis
Palestra Java + NoSQL = Iniciativa JNoSQL  no TDC FlorianópolisPalestra Java + NoSQL = Iniciativa JNoSQL  no TDC Florianópolis
Palestra Java + NoSQL = Iniciativa JNoSQL no TDC Florianópolis
Marcelo Souza Vieira
 
Javascript in C# for Lightweight Applications
Javascript in C# for Lightweight ApplicationsJavascript in C# for Lightweight Applications
Javascript in C# for Lightweight Applications
VelanSalis
 

What's hot (20)

AJAX
AJAXAJAX
AJAX
 
Google cloud datastore driver for Google Apps Script DB abstraction
Google cloud datastore driver for Google Apps Script DB abstractionGoogle cloud datastore driver for Google Apps Script DB abstraction
Google cloud datastore driver for Google Apps Script DB abstraction
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
Ajax
AjaxAjax
Ajax
 
Get docs from sp doc library
Get docs from sp doc libraryGet docs from sp doc library
Get docs from sp doc library
 
Xml And JSON Java
Xml And JSON JavaXml And JSON Java
Xml And JSON Java
 
Web Development Course - AJAX & JSON by RSOLUTIONS
Web Development Course - AJAX & JSON by RSOLUTIONSWeb Development Course - AJAX & JSON by RSOLUTIONS
Web Development Course - AJAX & JSON by RSOLUTIONS
 
Ajax Presentation
Ajax PresentationAjax Presentation
Ajax Presentation
 
Ajax and PHP
Ajax and PHPAjax and PHP
Ajax and PHP
 
Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access
 
Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012
 
OrientDB
OrientDBOrientDB
OrientDB
 
Ajax Introduction
Ajax IntroductionAjax Introduction
Ajax Introduction
 
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
 
phptut4
phptut4phptut4
phptut4
 
Ajax xml json
Ajax xml jsonAjax xml json
Ajax xml json
 
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
 
Palestra Java + NoSQL = Iniciativa JNoSQL no TDC Florianópolis
Palestra Java + NoSQL = Iniciativa JNoSQL  no TDC FlorianópolisPalestra Java + NoSQL = Iniciativa JNoSQL  no TDC Florianópolis
Palestra Java + NoSQL = Iniciativa JNoSQL no TDC Florianópolis
 
Javascript in C# for Lightweight Applications
Javascript in C# for Lightweight ApplicationsJavascript in C# for Lightweight Applications
Javascript in C# for Lightweight Applications
 

Similar to Lec 7

AJAX.pptx
AJAX.pptxAJAX.pptx
AJAX.pptx
ssuser0a07a1
 
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.
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
Raja V
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
Adnan Sohail
 
Ajax
AjaxAjax
Ajax
Yoga Raja
 
Unit-5.pptx
Unit-5.pptxUnit-5.pptx
Unit-5.pptx
itzkuu01
 
Implementing AJAX in PHP. Asynchronous JavaScript and XML
Implementing AJAX in PHP. Asynchronous JavaScript and XMLImplementing AJAX in PHP. Asynchronous JavaScript and XML
Implementing AJAX in PHP. Asynchronous JavaScript and XML
SanthiNivas
 
Ajax and xml
Ajax and xmlAjax and xml
Ajax and xml
sawsan slii
 
Ajax
AjaxAjax
Ajax
Svirid
 
AJAX and JSON
AJAX and JSONAJAX and JSON
AJAX and JSON
Julie Iskander
 
Ajax
AjaxAjax
Ajax Fundamentals Web Applications
Ajax Fundamentals Web ApplicationsAjax Fundamentals Web Applications
Ajax Fundamentals Web Applicationsdominion
 
jQuery - Chapter 5 - Ajax
jQuery - Chapter 5 -  AjaxjQuery - Chapter 5 -  Ajax
jQuery - Chapter 5 - Ajax
WebStackAcademy
 
AJAX.pptx
AJAX.pptxAJAX.pptx
AJAX.pptx
Ganesh Chavan
 

Similar to Lec 7 (20)

AJAX.pptx
AJAX.pptxAJAX.pptx
AJAX.pptx
 
Core Java tutorial at Unit Nexus
Core Java tutorial at Unit NexusCore Java tutorial at Unit Nexus
Core Java tutorial at Unit Nexus
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
 
Ajax
AjaxAjax
Ajax
 
Unit-5.pptx
Unit-5.pptxUnit-5.pptx
Unit-5.pptx
 
Ajax
AjaxAjax
Ajax
 
Implementing AJAX in PHP. Asynchronous JavaScript and XML
Implementing AJAX in PHP. Asynchronous JavaScript and XMLImplementing AJAX in PHP. Asynchronous JavaScript and XML
Implementing AJAX in PHP. Asynchronous JavaScript and XML
 
Ajax Tuturial
Ajax TuturialAjax Tuturial
Ajax Tuturial
 
Ajax and xml
Ajax and xmlAjax and xml
Ajax and xml
 
Copy of ajax tutorial
Copy of ajax tutorialCopy of ajax tutorial
Copy of ajax tutorial
 
Xml http request
Xml http requestXml http request
Xml http request
 
Ajax
AjaxAjax
Ajax
 
AJAX and JSON
AJAX and JSONAJAX and JSON
AJAX and JSON
 
Ajax
AjaxAjax
Ajax
 
Ajax Fundamentals Web Applications
Ajax Fundamentals Web ApplicationsAjax Fundamentals Web Applications
Ajax Fundamentals Web Applications
 
Mashup
MashupMashup
Mashup
 
jQuery - Chapter 5 - Ajax
jQuery - Chapter 5 -  AjaxjQuery - Chapter 5 -  Ajax
jQuery - Chapter 5 - Ajax
 
AJAX.pptx
AJAX.pptxAJAX.pptx
AJAX.pptx
 
Ajax
AjaxAjax
Ajax
 

More from maamir farooq

Ooad lab1
Ooad lab1Ooad lab1
Ooad lab1
maamir farooq
 
Lesson 03
Lesson 03Lesson 03
Lesson 03
maamir farooq
 
Lesson 02
Lesson 02Lesson 02
Lesson 02
maamir farooq
 
Php client libray
Php client librayPhp client libray
Php client libray
maamir farooq
 
Swiftmailer
SwiftmailerSwiftmailer
Swiftmailer
maamir farooq
 
Lect15
Lect15Lect15
Lec 6
Lec 6Lec 6
Lec 5
Lec 5Lec 5
J query 1.7 cheat sheet
J query 1.7 cheat sheetJ query 1.7 cheat sheet
J query 1.7 cheat sheet
maamir farooq
 
Assignment
AssignmentAssignment
Assignment
maamir farooq
 
Java script summary
Java script summaryJava script summary
Java script summary
maamir farooq
 
Lec 3
Lec 3Lec 3
Lec 1
Lec 1Lec 1
Css summary
Css summaryCss summary
Css summary
maamir farooq
 
Manual of image processing lab
Manual of image processing labManual of image processing lab
Manual of image processing lab
maamir farooq
 
Session management
Session managementSession management
Session management
maamir farooq
 
Data management
Data managementData management
Data management
maamir farooq
 
Content provider
Content providerContent provider
Content provider
maamir farooq
 
Android sq lite database tutorial
Android sq lite database tutorialAndroid sq lite database tutorial
Android sq lite database tutorial
maamir farooq
 

More from maamir farooq (20)

Ooad lab1
Ooad lab1Ooad lab1
Ooad lab1
 
Lesson 03
Lesson 03Lesson 03
Lesson 03
 
Lesson 02
Lesson 02Lesson 02
Lesson 02
 
Php client libray
Php client librayPhp client libray
Php client libray
 
Swiftmailer
SwiftmailerSwiftmailer
Swiftmailer
 
Lect15
Lect15Lect15
Lect15
 
Lec 6
Lec 6Lec 6
Lec 6
 
Lec 5
Lec 5Lec 5
Lec 5
 
J query 1.7 cheat sheet
J query 1.7 cheat sheetJ query 1.7 cheat sheet
J query 1.7 cheat sheet
 
Assignment
AssignmentAssignment
Assignment
 
Java script summary
Java script summaryJava script summary
Java script summary
 
Lec 3
Lec 3Lec 3
Lec 3
 
Lec 2
Lec 2Lec 2
Lec 2
 
Lec 1
Lec 1Lec 1
Lec 1
 
Css summary
Css summaryCss summary
Css summary
 
Manual of image processing lab
Manual of image processing labManual of image processing lab
Manual of image processing lab
 
Session management
Session managementSession management
Session management
 
Data management
Data managementData management
Data management
 
Content provider
Content providerContent provider
Content provider
 
Android sq lite database tutorial
Android sq lite database tutorialAndroid sq lite database tutorial
Android sq lite database tutorial
 

Recently uploaded

How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
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
 
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
 
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
 
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
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 

Recently uploaded (20)

How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
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
 
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
 
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
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 

Lec 7

  • 1. Web Technologies – CS 382 Shehzad Aslam Lecture 7 2 Hr
  • 2.  AJAX introduction  Where t use AJAX  Combining AJAX with JSON  Review of JavaScript Object & JSON  AJAX with simple JavaScript
  • 3.  Asynchronous JavaScript and XML  Technique for creating better, faster, and more interactive web applications  Uses XHTML for content with DOM & JavaScript to display dynamic content  Traditional Page is synchronous  You submit form, hit enter and wait to be redirected to another page  AJAX is Asynchronous  Will make a background request and update the page, while you are doing other things in the page  Where to use  Scroll a page, some of the contents will load after scroll (just like Google image search)  Do chat, after certain time pull new contents  Notifications, after certain time pull new notification  Tell that you are active; after certain time ping server with some data  When doing search, show hits; or provide some data, remaining will be filled Use where you do not want to reload page
  • 4.  Runs on browser not Server  Not a language, can say a technique or Library  Basically Designed for XML Response  But can use any data format (plain text, XML, CSV, JSON, HTML etc)  Behind the scene, HTTP request is sent  Powerful use is in searching & forms submission, chat, notifications etc  Real Examples  Comments pull on youtube  Search hints in Google or on some site  Like option in Facebook  Next posts pull on Facebook  Cricket score updates  … and much more
  • 5. User interface Browser Database Web server http request HTML+CSS Data User interface Browser Database Web server http request XML Data AJAX Engine Javascript call HTML CSS data Classic web app model AJAX web app model
  • 6.
  • 7.  Create XHR (XML HTTP Request) Object  Create a function that will be called when request status change  It will be a callback function  Use the data, modify the DOM or what ever you want  Set options  where to fetch/send data  what is the method  Want Asynchronous or not  What is HTTP authentication username  What is HTTP authentication password  Initiate the connection
  • 8. var xhr = new XMLHttpRequest(); //object //callback function xhr.onreadystatechange = function () { //check ready state //check server response code, based on that use data or show error }; //set request parameters xhr.open(method, url, [asyn/synch, username, pwd]); //e.g. xhr.open(“GET”, “http://uet.edy.pk”, true); //call it on some event xhr.send();
  • 9.  abort()  Cancel current request  getAllResponseHeaders()  Get all headers as string  getResponseHeader(headerName)  Get all specific headers  open(method, url, async, username, pwd)  Specify options  PUT, DELETE may not possible  send(contents)  Sent the request  setRequestHeader(header, value)  Add header to be sent to server
  • 10.  status  Response status code e.g 200, 404 etc  statusText  Response status text e.g. OK, Not Found etc  readyState  Information about the current request object (it is a number 0-4)  onreadystatechange  An event handler that is fired at every state change  responseText  Response as a string  responseXML  Response as XML
  • 11.  readyState property defines current state of XMLHttpRequest object State Description 0 Request is not initialized - Created object but not called open yet 1 Request has been setup - after open has been called but sent not called yet (connected to server) 2 Request has been sent - After send has been called 3 Request is in process - browser established a communication but before server completed response 4 Request has been completed - request completed, all the response received, data ready
  • 12.  AJAX not supported by Old browsers  All modern browsers (Chrome, IE7+, Firefox, Safari, and Opera) have a built-in XMLHttpRequest object  Variable = new XMLHttpRequest();  Old versions of Internet Explorer (IE5 and IE6) use an ActiveX Object  variable = new ActiveXObject("Microsoft.XMLHTTP"); var xhttp; if (window.XMLHttpRequest) { xhttp = new XMLHttpRequest(); } else { // code for IE6, IE5 xhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  • 13. var counting= [1,2,3,4]; Will be [ 1, 2, 3, 4 ] var name = [“Ali”, “Umer”]; Will be [ “Ali”, “Umer” ]
  • 14. Java Script Object Notation var objectname = { property: value, property:value }; Will be { “property”:value, “property”:value, } var fish= { name: “tuna”, weight:150, color: “black & gray” }; ? { “name”: “tuna”, “weight”:150, “color”: “black & gray” } Just like so mixed objects This data could be in new file with json extension
  • 15.  Currently we are fetching static contents  hold until we get our hands on PHP  You are provided a folder  Place it in www dir of WAMP  Create a copy of sample page  Create a button, define onclick event and do following  Fetch lect7/data/foods/fruits.json and display using AJAX  List the fruits  Create a copy of sample page  Create a button, define onclick event and do following  Fetch lect7/data/animals/birds_antarctica.json and display using AJAX  Family as h2 and members are as unordered list  Problem  JSON not turning to object  jsonObject = JSON.parse(jsonString);  jQuery.parseJSON( jsonString );
  • 16.  Create a copy of sample page  Create a button, define onclick event and do following  Fetch lec7/data/story.txt and display in a div using AJAX  Do same for to get lec7/data/story.html and display in new div  Create new div & do following  Create a button, define onclick event and do following  Fetch lec7/data/story.json and display in a div using AJAX  Title in h1, author in h3, description in italic & story text simple in each line  Fetch lect7/data/colors/web_colors.json  Show it in table having one column  and each row background is hex color given & contents are color name  Fetch lect7/data/colors/palettes.json  Show it in table having four column  and each cell background is hex color given & contents are color code  Fetch lect7/data/foods/vegetable_cooking_times.json  Show detail
  • 17.  Represent RCET, UET, KSK in JSON with following details. Use AJAX to get data and display on the page  Departments (array)  Each department having name, hod name, faculty list (each faculty name, qualification), no of students in each session  Cafeteria (array) with list of food items each item having category, served weight and price  Playgrounds (array) with description, area  Hostels (array) with name, warden, rooms (array) with each room resident name  Represent your time table in JSON  Use AJAX to show it just like time table  * Separate the data that you were changing in the last assignment  Create some json files having some data in same format, name of file is vourcherno  When you change the voucher no use AJAX to get data related to that voucherno & show
  • 18.  Is there a batter way to create HTML with JavaScript  Yes! But We used string concatenation  See Handlebars.js  Practice with given JSON files