pf » AJAX Presentation Outline
AJAX Presentation Outline

Here's an outline of the presentation on AJAX that I gave today at my ColdFusion users group meeting.
What is AJAX?
- Asynchronous JavaScript + XML
- XMLHttpRequest Object
- A geek marketing term
- Rich Internet Applications with JavaScript
Examples of AJAX
- GMail
- Google Maps
- Basecamp
Is it new?
- Not Really
- Hidden Frames
- IE5+, Mozilla 1.0+, Safari 1.2+, and Opera 7.6+
Why is it popular?
- Google helped popularize, and legitimize it in GMail
- Increase Usability of Web Applications
- Rich Internet Applications without Flash
- Save Bandwidth
- Download only data you need
- Faster interfaces (sometimes)
Why is it bad?
- Breaks back button support
- URL's don't change as state changes
- Cross Browser Issues can be a pain
- JavaScript may tax older machines CPU
- Can't access domains other than the calling domain
- May be disabled (for security reasons) or not availiable on some browsers
Flash vs AJAX
- No plugin for AJAX
- Flash development tools cost money
- Flash typically has slower page load time
- Flash can work on older browsers
- ActionScript doesn't havea cross browser issues
- Flash can access other domains if there is a crossdomain.xml file
XMLHttpRequest
- A JavaScript Class that lets you make asynchronous HTTP requests from JavaScript
- Make an HTTP request from a JavaScript event
- A call back JavaScript function is invoked at each state of the HTTP request and response
XMLHttpRequest Properties
- onreadystatechange - call back function for state changes
- readyState - the current state of the HTTP call
- responseText - the text result of the request
- responseXML - DOM xml object from the request
- status - HTTP status code of the response
- statusText - HTTP status text
XMLHttpRequest Example
if (window.XMLHttpRequest) {
var req = new XMLHttpRequest();
req.onreadystatechange = requestStateHandler;
req.open("GET", "/somefile.xml", true);
req.send("");
}
function requestStateHandler() {
if (req.readyState == 4) { //response ready
alert(req.statusText);
}
}
IE does it different
- The above example however won't work on IE
req = new ActiveXOjbect("Microsoft.XMLHTTP");- You can't totally blame them because they invented it
- Native XMLHttpRequest support should be in IE7
Cross Browser AJAX
var req;
function loadXMLDoc(url) {
req = false;
// branch for native XMLHttpRequest object
if(window.XMLHttpRequest) {
try {
req = new XMLHttpRequest();
} catch(e) {
req = false;
}
// branch for IE/Windows ActiveX version
} else if(window.ActiveXObject) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
req = false;
}
}
}
if(req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send("");
}
}
Source: http://developer.apple.com/internet/webcontent/xmlhttpreq.html - a great AJAX tutorial BTW.
AJAX Libraries
- Many people opt for AJAX libraries. This can ease development, but also adds bloat.
Prototype Example
I posted the AJAX prototype example that I showed in the presentation in another entry.
add to del.icio.us
| Tags: ajax, presentation, xmlhttprequest, javascript, xml
Related Entries
- AJAX Tutorial with Prototype - December 13, 2005
- AJAX on IE - back to the IFRAME - August 17, 2005
- Adobe AIR Tutorial for HTML / JavaScript Developers - February 25, 2008
- Ext CFC - December 12, 2007
- GoogleBot Runs AJAX? - December 6, 2006
- The Ajax buzz Christoph Schmitz
- Cold Fusion + Prototype Ajax presentation and example code Ajaxian
2. I've found sending Javascript arrays rather than XML from CF to the browser faster and easier. Less code and Javascript is brilliant for working with arrays, especially if you use short notation to create them which CF can do with minimal code. e.g. var myArray=[ ["value","key"], ["value","key"] ];
You can read my blog via http://rayhorn.contentopia.net/blog
But yes I agree the IFRAME method is better for some apps.
As for the ColdFusion side, extending an base class makes it extremely easy for the CF developer. All he has to do is write a function just as if he would write it for a CF page& nothing changes& the ajax call will do the rest. For your second comment, I concur. ajaxCFC sends JavaScript arrays back to the browser instead of XML, and its automatically picked up by the call-back function; not in key pairs like you mentioned, but real arrays and structures& I hate to loop over an array and check for a key pair& there are more efficient ways of handling recordsets.
As far a cross domain, get vebs do work. I would personally stay away from the iframe method & I used that about 5 or 6 years ago & Its no longer needed.
Not giant martketshare of course, but most Mac users I know are using Safari if they've made the OS X transition.
Mac's do not have a huge marketshare, although I work with dozens of ad agencies, and they all use them& so I definitely have to accommodate for that.
However, I disagree with you on IE& I do not like IE, especially from a developer stand point& it's _intelligence_ auto fixes bad css and bad JS syntax, making it work only on IE and not in any other browser & but at least it works & Safari on the other hand gives me a headache every time I need to ensure that the L&F will look the same as IE or FF.
Back to AJAX and Safari & Safari requires some tweaking to work properly & it auto encodes XML request packets, so you need to know to decode them before using them in the server side & and then DOM & I hear Safari 2.0 fixed some issues, but again, 1.3 is missing a vast amount of functionality, making it extremely more difficult to develop nice Web 2.0 applications.
I don't have nearly the experience that you do in this realm, so wouldn't dream of arguing the finer points of the good, bad and ugly of the many ways in which the plethora of browsers out there wreak havoc, making coding by multiple exceptions or lowest common denomiator the norm. Sounds like we're in agreement in general there in any case. None of these browsers is perfect, eh?
On the AJAX front, I definitely agree that IE/Win has much more going for it, since Microsoft did after all invent the XMLHttpRequest Object (an overnite sensation after only 5, 7 years?) - but the giant stack of bugs relating to CSS, HTML, XHTML that everyone is forced to learn to get even basic pages/sites into reasonable shape is enough to drive one to drink! My experience thus far is that Safari tends to act much like Firefox on the display side, which tends to simplify at least SOME of the work.
Layering on top of those issues, the fun in dealing with AJAX/Web 2.0 functionality - I heartily applaud you and the other folks that are blazing a path here and sorting out the bugs to create such a more dynamic and fluid web experience. 2005 has been a heck of year for this, eh? Looking forward to 2006.
Looking back at your last comment incidentally - sites that I have worked on, or other companies that I have asked about traffic patterns seem to register more Safari 2.x users than prior versions, for the Mac traffic that they are getting.
Sounds as though the users for your sites/projects haven't leashed themselves a Tiger yet - a shame for them to miss out on the better Safari experience, speed bump (every version of OS X is faster than the last - what a concept) and far more solid OS in Tiger.
Cheers, Dan
(ah, and to make sure I'm not hallucinating - do you have a book on AJAX out? If so, I'm not finding it via Google, Amazon, etc.)
I wasn't talking about some specific users; I am CTO for iChameleon Group (www.ichameleongroup.com) and I look at stats for all our major sites. For example, these stats come from a site that I cannot disclose, with about 500,000 unique hits a month.
83% IE 10% FF 3.8% Safari
About 50% are 1.3 and 50% 2.0 ... so about 1.9% of my average users use Safari 1.3, lol...
And if I look at my international sites, i.e. for South America, it's actually 0%.
Anyways, back to the point ... I just ran into a problem yesterday ... I wrote a form validation tool in ColdFusion to mimic Flex 2.0 functionality, and I found that it works perfectly in IE, FF, Opera, Netscape, but Safari does not want to color the borders of the required inputs; small CSS compatibility issue. I also had issues auto resizing iframes... and huge issues with Flash ... especially performance, and streaming flv's, but those two are Macs in general ...
AJAX for Safari works perfectly after I decode the URL string in the server side.
Btw, thanks for the complements... but I didn't write a book ? not yet at least --. I wrote some articles for sys-con, I am speaking at a couple of seminars, a webcast for Reuters, and developed a ColdFusion-Ajax framework :) ... but I still haven't had time for a full book... good idea though, I will consider it.
Check out (sorry for the spam) :) http://coldfusion.sys-con.com/read/138966.htm http://coldfusion.sys-con.com/read/154244.htm http://www.ajaxseminar.com/ http://www.robgonda.com/blog/projects/ajaxcfc/
oh yes... I am so glad Microsoft publicly announced they ceased support for IE for Macs: http://www.microsoft.com/mac/products/internetexplorer/internetexplorer.aspx?id=internetexplorer
Best,
-Rob
I have not spoken to the Safari team, but you might want to get in touch with Dave Hyatt and that crew (http://webkit.opendarwin.org/blog/) to report the issues you've mentioned. I do agree though, for some reason Flash can have very poor performance characteristics on Macs.
Having peered a fair amount into the book writing/publishing process (several of our people at Delphi Group - http://www.delphigroup.com/ - have written books over the years), I wouldn't necessarily recommend doing it - particularly for technical writing, it's quite a process to go through. Be prepared to lose whatever spare time and previously occupied time you had to the process! But Fame (perhaps) and fortune (not quite) are yours to be had! :)
Articles, seminars, webcasts - much easier to make progress on in reasonable amounts of time and effort...
If all of these technologies just worked as they would, what would we all do with our spare time?
Great chatting with you here - and I'm sure we'll run into each other here or elsewhere in the "blogosphere" - keep up the good work.
Cheers, Dan
IE 5+ Mozilla (all) Netscape 7+ Safari 1.2+ Opera 7.6+
That's about 90% or more user-base for most websites.
req = new ActiveXOjbect("Microsoft.XMLHTTP");
(object is spelled "ojbect") which won't work when you cut and paste the line as I did. :)
Please give me some DOCUMENT regarding AJAX, it will be help full for me
- CFSCRIPT Cheatsheet
- 3 New Image Effects for ColdFusion 8
- Googlebot to Submit Web Forms
- ColdFusion 8 Update 1 Fixes some Image Processing Quirks
- 10 Most Useful Image Functions in ColdFusion 8
- Speaking at NYC CFUG This Week
- Adobe AIR Tutorial for HTML / JavaScript Developers
- INFORMATION_SCHEMA Support in MySQL, PostgreSQL
RSS
Pete Freitag is a software engineer, and web developer located in









