Professional Documents
Culture Documents
A SEMINAR REPORT ON
Guided by Prepared by
Ms. Niti A. Desai Trivedi Vighnesh K.
Co-Guided by
Mr. Bintu Kadhiwala
Page 1 of 27
AJAX- The Web Development Technique
CERTIFICATE
Page 2 of 27
AJAX- The Web Development Technique
Acknowledgement
I am very thankful to Ms. Niti A. Desai and Mr. Bintu Khadhiwala who guided me
and suggested me many ideas. I am also thankful to other faculty members of
Computer/Information Technology Department.
I am also thankful to Mr. Keyur Rana, the DIC (Computer Engg. Dept.) of Sarvajanik
College of Engineering and Technology for his unconditional and unbiased support.
I also want to thank to all my friends who helped me a lot during preparation of my
seminar presentation.
Page 3 of 27
AJAX- The Web Development Technique
Abstract
7
2 005 w il l de f init ely be r emem ber ed as the r i se of A J AX – the n ew
dev el o p ment te chnique tha t m an y be lie ve w il l blur t he l ine betw ee n w eb- b as ed
a nd d es k to p a pplica tions . Thi s m yst ica l acr onym , author e d by A da ptive P ath i n
m id F eb r u a r y, is a la bel f or the r ich, hi ghly r es pons ive and i nter a ctive inte r f aces
of AJ A X- e n able d applic ati ons.
AJAX is used by many popular internet companies such as Google Suggests, Google and
Yahoo! maps, Amazon A9 Search, Flickr, BaseCamp, Kayak Yahoo! AJAX library. The future
of AJAX is bright. Think about the possibilities that giving User almost “live” feedback when
they interact with the web application you have Designed and developed.
Page 4 of 27
AJAX- The Web Development Technique
INDEX
3. What is AJAX? 3
5. Benefits of AJAX 6
14. Conclusion 20
15. References 21
Page 5 of 27
AJAX- The Web Development Technique
Page 6 of 27
AJAX- The Web Development Technique
• Desktop Application
• Web Application
These are both familiar; desktop applications usually come on a CD (or sometimes are
downloaded from a Web site) and install completely on your computer. They might use the Internet to
download updates, but the code that runs these applications resides on your desktop. Web applications --
and there's no surprise here -- run on a Web server somewhere and you access the application with your
Web browser.
More important than where the code for these applications runs, though, is how the applications
behave and how you interact with them. Desktop applications are usually pretty fast (they're running on
your computer; you're not waiting on an Internet connection), have great user interfaces (usually
interacting with your operating system), and are incredibly dynamic. You can click, point, type, pull up
menus and sub-menus, and cruise around, with almost no waiting around.
On the other hand, Web applications are usually up-to-the-second current and they provide
services you could never get on your desktop (think about Amazon.com and eBay). However, with the
power of the Web comes waiting -- waiting for a server to respond, waiting for a screen to refresh, and
waiting for a request to come back and generate a new page. Thus in the web application it takes much
more time to complete the request and all this time what the user do is just waiting for result to arrive.
So it takes longer time to complete the request.
Page 7 of 27
AJAX- The Web Development Technique
What is Ajax?
Of Adaptive Path made a good case for using Asynchronous JavaScript and XML and coined the
acronym "AJAX" to represent that notion. It is similar to the Remote IFrame technique in that things are
handled on the client side, but as we shall see differs in significant ways.
Page 8 of 27
AJAX- The Web Development Technique
Ajax isn’t a technology. It’s really several technologies, each flourishing in its own right, coming
together in powerful new ways. Ajax incorporates:
• Standards-based presentation using XHTML and CSS
W h at' s even mor e int er es ting is t hat A JA X is actua lly not a t echnol ogy. I t is
m or e l ik e a developm ent t echnique that util izes in a unique w ay a num b er o f
a lr e ad y mat u r e te chnologi es:
The classic web application model works like this: Most user actions in the interface trigger an
HTTP request back to a web server. The server does some processing — retrieving data, crunching
Page 9 of 27
AJAX- The Web Development Technique
numbers, talking to various legacy systems — and then returns an HTML page to the client. It’s a model
adapted from the Web’s original use as a hypertext medium, but as fans of The Elements of User
Experience know, what makes the Web good for hypertext doesn’t necessarily make it good for
software applications.
Figure 1: The traditional model for web applications (left) compared to the Ajax model (right).
This approach makes a lot of technical sense, but it doesn’t make for a great user experience.
While the server is doing its thing, what’s the user doing? That’s right, waiting. And at every step in a
task, the user waits some more.
Page 10 of 27
AJAX- The Web Development Technique
Obviously, if we were designing the Web from scratch for applications, we wouldn’t make users
wait around. Once an interface is loaded, why should the user interaction come to a halt every time the
application needs something from the server? In fact, why should the user see the application go to the
server at all?
Instead of loading a webpage, at the start of the session, the browser loads an Ajax engine —
written in JavaScript and usually tucked away in a hidden frame. This engine is responsible for both
rendering the interface the user sees and communicating with the server on the user’s behalf. The Ajax
engine allows the user’s interaction with the application to happen asynchronously — independent of
communication with the server. So the user is never staring at a blank browser window and an hourglass
icon, waiting around for the server to do something.
Page 11 of 27
AJAX- The Web Development Technique
Figure 2: The synchronous interaction pattern of a traditional web application (top) compared with the
asynchronous pattern of an Ajax application (bottom).
Every user action that normally would generate an HTTP request takes the form of a JavaScript
call to the Ajax engine instead. Any response to a user action that doesn’t require a trip back to the
server — such as simple data validation, editing data in memory, and even some navigation — the
engine handles on its own. If the engine needs something from the server in order to respond — if it’s
submitting data for processing, loading additional interface code, or retrieving new data — the engine
makes those requests asynchronously, usually using XML, without stalling a user’s interaction with the
application.
Benefits of Ajax
Page 12 of 27
AJAX- The Web Development Technique
Page 13 of 27
AJAX- The Web Development Technique
Page 14 of 27
AJAX- The Web Development Technique
• M ain t a in s t h e Page V iew S t at e B et w een Cal lb ack s – this is the bi ggest ob s ta cle
w he n u si n g AJ A X. S inc e no pos t backs ar e per f or med, w eb c ontr ols w ill n o t
m ai n tai n th ei r Vi ew S t ate a utoma tica lly. I t is up to the develope r or the c ommer c ial
A JA X c o mp o nent to ens ur e tha t the Vi ew St ate of a ll c ontr ols on the page r ef l ects
t hei r cu r r en t st ate. I f t his is not tr u e , your appli cati on wi ll not wor k pr ope r ly.
• P re se rv e t he N orm al Page L if ec ycle – mos t we b appl icat ions ne ed t o us e a m ix o f
A JA X cal lb ac ks and r egular pos t b a cks . A s a r es ult you have t o ma ke s ur e th at t h e
A JA X c o mp o n ent s you c hoose w il l pr oper l y subm it on pos t ba ck the c or r ect f o r m
d ata to th e ser ve r af te r numer ous cal lback upda tes have be en ma de.
• R ef lec t s C o n t rol S t at e on t h e S erver – in r ea l- li f e s cenar i os t her e is no u s e o f
s imp ly r en d er i ng c ontr ols on the page. Y ou w ill a ls o nee d to get the val ues of in p u t
c on tr o l s ( i . e. get the val ue of a t extbox or the checke d st ate of a chec kbo x ) f o r
s er v er - s id e p r oces s ing, a s we ll as t o s et the val ues w hen t he r e spons e is f o r m ed .
T her e f o r e, th e A J AX com ponents you choos e mus t be able to pr oper ly r e f lec t o n th e
s er v er t h e cu r r ent s tate of all w eb contr ols , jus t l ike thi s is done dur ing r egula r p o s t
b ack s .
• U pd a t e 3 rd P art y Con t rol s w it h C om p lex JavaS cri p t – due to t he f act that man y
A SP . N ET a p plica tion us e c ommer c ial 3r d par ty cont r ols ( e.g. pow er f ul da ta g r id s ,
t ree v ie ws , WYS I WY G e ditor s , e tc.) , your A J AX c omponent s mus t be a b le to
p r op er ly u p d a te s uch cont r ols . The bi gges t pr oblem her e i s t hat 3r d par t y co n tr o l s
o f ten use c omplex J avaS cr ipt , w hic h is damage d by univer s al A JA X
Page 15 of 27
AJAX- The Web Development Technique
w ra p p er s /co n t ainer s . Thi s dr a wba ck make s s uch w r apper s pr ac tica lly unus abl e f o r
t he m ajo r i ty of mode r n AS P .NE T appl icat ions .
• C ro ss - B ro w s er Su p p ort – w r it ing c r oss - br ow se r com pati ble AJ A X compone n ts i s a
b ig ch a lle n g e due to t he dif f e r ent im plem enta tion of t he Xm lH ttpR e ques t o b je ct.
T her e f o r e, y o u s hould make sur e that all A J AX com ponents you choos e op er a te
p r op er ly o n v a r ious br ows er s and pla tf or ms .
• P rop er Op er at ion w h en C ook ies ar e d is ab led – anothe r r equi r eme nt r e lat ed t o
w id e ap p l icat ion com pati bili ty is the suppor t f or cookie l es s s es s ions .
Page 16 of 27
AJAX- The Web Development Technique
F u r th er mo r e , s ome acc es si bili ty s ta ndar ds pr ohibi t the use of Ja vaS cr ipt al togeth e r ,
w hi ch p r ac tica lly e lim inat es t he pos si bili ty f or us ing A JA X .
• N ew U I In t er act ivi t y Req u ir es L e arn in g – the U I r ic hnes s of A J AX - enab l ed
a pp li cat io n i ntr oduce s pr es ents us er s w it h ne w and une xpect ed f unc tion al ity .
A lth o u g h th i s i s t he ma in r eas on f or us ing A JA X in the f ir s t pla ce, it may r e q u ir e
s om e le ar n in g.
JavaScript Code
The AjaxScript.js file includes the required AJAX script. When the selected value of the country
drop-down list changes, the CountryListOnChange function is called. Now we will talk about how the
asynchronous request to the server in the CountryListOnChange function works.
1. Form the request URL with the selected country in the query string.
2. The CreateXmlHttp function (this function is explained in the earlier section, Creating an Instance of
an XMLHTTPRequest Object) creates an instance of an XMLHTTP request object. If the browser does
not support the XMLHTTP object, the XmlHttp variable will be set to null and the AJAX code will not
be executed. If the browser supports the XMLHTTP object, an asynchronous request is submitted to the
server using the XMLHTTP object.
3. The onreadystatechange property of the XMLHTTP object is used to set the response handler for the
asynchronous request. This response handler gets called for every change of readyState property of the
XMLHTTP object. In our code we set the HandleResponse function as the response handler.
4. The open method is called to initialize the request. The first parameter of the open method takes
a method definition (GET, POST, etc.), in our case its GET. The second parameter takes the request
URL. The third parameter takes a Boolean value indicating whether the request submitted is
synchronous or asynchronous. In our sample its asynchronous, so the third parameter is set to true.
Other parameters are optional; we do not use them in our application.
5. The send method submits the request to the server. The send method's behavior is determined by the
third parameter of the open method. In our case it is true, so the send function behaves as an
asynchronous function, which means that the browser calls the send function and does not wait for the
response to come back from the server.
When the response comes back from the server, the HandleResponse function (Listing 6) gets
called. In fact, the HandleResponse function is called for every change of the readyState property of the
XMLHTTP object. The readyState property can take a value from 0 to 4 (0=UNINITIALIZED,
Page 17 of 27
AJAX- The Web Development Technique
If the readyState of the XMLHTTP instance has a value of 4, we then need to check its status
property to make sure that a valid response was received. The status property holds the HTTP status
code returned from the server. A value of 200 means that data received in the request is OK. Some of
the other popular HTTP status codes, with which most developers are familiar, are 404 (page not found),
403 (access forbidden), and 500 (internal server error). We check that the XmlHttp.status property is
200 to make sure that the response received has a status of OK. The responseXML property of the
XMLHTTP object returns an XML document. This property is useful only when the response from the
server is in XML format. In our sample, the response is a list of states in XML format. If both conditions
are satisfied (readyState is 4 and status is 200), we call the function ClearAndSetStateListItems with the
XML document as an input parameter.
JavaScript
var AjaxServerPageName;
AjaxServerPageName = "AjaxServer.aspx";
//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp”
variable
function CreateXmlHttp()
{
//Creating object of XMLHTTP in IE
try
{
XmlHttp = new ActiveXObject ("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
Page 18 of 27
AJAX- The Web Development Technique
(XmlHttp.responseXML.documentElement);
}
else
{
alert("There was a problem retrieving data from the
server." );
}
}
}
//Clears the contents of state combo box and adds the states of currently selected country
function ClearAndSetStateListItems(countryNode)
{
var stateList = document.getElementById("stateList");
//Clears the state combo box contents.
for (var count = stateList.options.length-1; count >-1; count--)
{
stateList.options[count] = null;
}
When the page loads for the first time, this method populates the Country and State
DropDownList controls using the GetCountryList and GetStateList methods of CountryStateXml class.
{
countryList.Items.Add(countries[index].ToString());
}
//Getting the list of states for a given in an ArrayList
ArrayList states = countryStateXml.GetStateList(countries[0].ToString()) ;
To succeed - you must start with good planning. Efforts should be focused on reducing
and simplifying the AJAX calls, and creating a standard format for responses that follows
convention (ideally XML) where possible.
Follow best practice from sites such as the Open Web Application Security Project.
This especially includes checking for Access Control and Input Validation flaws, whilst ensuring
sensitive information travels over SSL rather than in the clear.
Never assume that Server Side AJAX checks for Access Control or User Input
Validation will replace the need for final re-checking at the Server. Adding AJAX controls will
never reduce your validation workload, they will only increase it.
Never assume that Client Side obfuscation (making the JavaScript difficult to read or
decode) will protect your most important commercial secrets. Using JavaScript is a poor way to
hide programming tricks and advances from your competitors.
You must be prepared to exercise a tight reign over your development team. Wonderful
ideas using AJAX may sound compelling, but you should consider saving them for version 2,
whilst you focus on building a rock-solid version 1.
Page 21 of 27
AJAX- The Web Development Technique
Drawbacks of Ajax
• Javascript has to be enabled. This rule out some browsing devices such as certain mobile terminals and
Lynx.
• The browser has to support the XMLHttpRequest object (or similar). Currently this is available in
Mozilla, Fire fox, Internet Explorer and Safari. Rumour has it that Opera will introduce it soon.
• Sure Ajax is cool, and developers love to play with cool technology, but Ajax is a tool not a toy. A lot of
the new Ajax applications are really just little toys, not developed for any real purpose, just experiments
in what Ajax can do or trying to fit Ajax somewhere where it isn’t needed. Toys might be fun for a little
while, but toys are not useful applications.
• The back button is a great feature of standard web site user interfaces. Unfortunately, the back button
doesn’t mesh very well with Javascript. Keeping back button functionality is a major reason not to go
with a pure Javascript web app.
• Not giving immediate visual cues for clicking widgets
If something I’m clicking on is triggering Ajax actions, you have to give me a visual cue that
something is going on. An example of this is GMail loading button that is in the top right. Whenever I
do something in GMail, a little red box in the top right indicates that the page is loading, to make up for
the fact that Ajax doesn’t trigger the normal web UI for new page loading.
The security of AJAX applications is subject to the same rules as any web application, except
that once you can talk asynchronously to the server, you may tend to write code that is a very chatty in a
potentially insecure way. All traffic must be vetted to make sure security is not compromised.
Ajax introduces a way to make much more interesting javascript applications, unfortunately
interesting often means more code running. More code running means more work for the browser,
which means that for some javascript intensive websites, especially poorly coded ones, you need to have
a powerful CPU to keep the functionality zippy. The CPU problem has actually been a limit on
javascript functionality in the past, and just because computers have gotten faster doesn’t mean the
problem has disappeared.
Page 22 of 27
AJAX- The Web Development Technique
• Not having a plan for those who do not enable or have JavaScript
According to the w3c browser usage staticts, which if anything are skewed towared advanced
browsers, 11% of all visitors don’t have javascript. So if your web application is wholly dependent on
javascript, you have immediately cut a tenth of your audience.
A major mistake that is easy to make with Ajax is: ‘click on this non obvious thing to drive this
other non obvious result’. Sure, users who use an application for a while may learn that if you click and
hold down the mouse on this div that you can then drag it and permanently move it to this other place,
but since that’s not in the common user experience, you increase the time and difficulty of learning your
application, which is a major negative for any application.
As I’ve referenced in a previous posting, Ajax applications introduce lots of problems for users
who assume GET operations don’t change state. Not only do state changing links cause problems for
robots, users who are accustomed to having links drive navigation can become confused when links are
used to drive application state changes.
The first A in Ajax stands for asynchronous. The problem with asynchronous messages is that
they can be quite confusing when they are pop in unexpectedly. Asynchronous page changes should
only ever occur in narrowly defined places and should be used judiciously, flashing and blinking in
messages in areas I don’t want to concentrate on harkens back to days of the html blink tag.
Another great feature of websites is that I can pass URLs to other people and they can see the
same thing that I’m seeing. I can also bookmark an index into my site navigation and come back to it
later. Javascript, and thus Ajax applications, can cause huge problems for this model of use. Since the
Javascript is dynamically generating the page instead of the server, the URL is cut out of the loop and
can no longer be used as an index into navigation. This is a very unfortunate feature to lose, many Ajax
webapps thoughtfully include specially constructed permalinks for this exact reason.
Page 23 of 27
AJAX- The Web Development Technique
Since Ajax/Javascript gives you such specific control over page content, it’s easy to get too
focused on a single area of content and miss the overall integrated picture. An example of this is the
Backpackit title. If you change a Backpackit page title, they immediately replace the title, they even
remember to replace the title on the right, but they don’t replace the head title tag with the new page
title. With Ajax you have to think about the whole picture even with localized changes.
Sure with Ajax you can make edits to a lot of form fields happen immediately, but that can cause
a lot of problems. For example if I check off a lot of check boxes that are each sent asynchronously to
the server, I lose my ability to keep track of the overall state of checkbox changes and the flood of
checkbox change indications will be annoying and disconcerting.
Another problem with popping text into a running page is that it can effect the page scroll. I may
be happily reading an article or paging through a long list, and an asynchronous javascript request will
decide to cut out a paragraph way above where I’m reading, cutting my reading flow off. This is
obviously annoying and it wastes my time trying to figure out my place.
• Blocking Spidering
Ajax applications that load large amounts of text without a reload can cause a big problem for
search engines. This goes back to the URL problem. If users can come in through search engines, the
text of the application needs to be somewhat static so that the spiders can read it.
Page 24 of 27
AJAX- The Web Development Technique
Pioneer of AJAX:
Now I describe you the websites that has implemented the AJAX in their web application:
1. Google Maps is one of the starters of implementing the ajax today most of the google
products are using ajax.
2. Websites providing email services like Gmail, Microsoft out look express also implements
ajax.
3. telerik has been recognized at the leading vendor of UI and data components for ASP.NET ,
providing professional developers with a comprehensive selection of tools for building rich
and highly interactive web applications. in telerik products like r.a.d.combobox and r.a.d.
grid were developed with internal support for AJAX. With the release of r.a.d. controls Q3
2005 and the introduction of the r.a.d. callback suite (part of r.a.d. controls). AJAX support
has been implemented across the full product line of ASP.NET components.
4. Microsoft has also released product Microsoft’s Atlas AJAX Web Development kit will have
an updated license allowing customers to run Web applications built Atlas.
6. DotNetNuke, the component which is built in vb.net enable to develop the websites of
enterprise level, has also implemented ajax in its new version DotNetNuke 3.4.0
Page 25 of 27
AJAX- The Web Development Technique
Conclusion
Over the years, desktop applications tried to a specific operating system have become entrenched as
the main way to work on a computer. AJAX, a set of development techniques standardized over the
past eight years, could change all that by bringing sophisticated interfaces to Web applications. With
that, backers are hoping it can open a crack in the domains of desktop software like Microsoft’s
Office, the undisputed market leader “. Zimbra is one of a growing number of companies that are
betting that AJAX, which stands for Asynchronous JavaScript + XML, will turn out to be more than
just a catchy abbreviation. In the development style, programmers use a number of standards – based
Web entrepreneurs and established software providers are hoping that AJAX can reinviogorate the
PC software buisness by marrying the graphical user interfaces of desktop computers with the
benefits of the Web.
AJAX frees Web pages from the clukiness they suffer from by making then more interactive and so
more functional , Web developers say.
From this we can surely say that use of ajax is going to be more and more and it will change the
apporch of Web development. No doubt, there will be modification in the ajax to enhance its power
but its usage will grow more and more as time goes on.
Page 26 of 27
AJAX- The Web Development Technique
Bibliography
http://www.telerik.com
http://adaptivepath.com
http://en.wikipedia.org/wiki/AJAX
http://www.ajaxseminar.com
http://www.doublecode.com/ajax-examples
http://www.clearnova.com/ajax/
Page 27 of 27