So How Do You Code an AJAX Web Page?
PetManimal writes "Computerworld has a long excerpt from a book by Edmond Woychowsky about how to code Web pages in AJAX. It gives a good explanation of how the technology works, and also has some visuals and code snippets that you can play with. From the article: 'Beyond the XMLHTTP Request object, which has been around for several years as a solution looking for a problem, there is nothing weird needed. Basically, it is how the individual pieces are put together. When they're put together in one way, it is nothing more than a pile of parts; however, when put together in another way, the monster essentially rises from its slab.'"
How do I save an AJAX page in a given state, rather than just a state that will be "rebooted" on reload from storage?
--
make install -not war
Print version here.
Zero credibility points for trying to put markup in the <title> element and hiding the printable version behind a javascript:void(0) link.
If you want the technical stuff, skip about a third of the way down. The first third of the article just repeatedly tells you that Ajax is when the page doesn't "blink".
The code he supplies is crap. For instance:
Things wrong with even this tiny snippet of code:
Skimming the rest of the article, I see the following mistakes:
If this is a representative sample of the book it is excerpted from, steer well clear of it. The whole approach is poor.
The best way of producing compatible, accessible Ajax applications is to start with the bare HTML and make that work. Only then do you add the JavaScript, and you do it by enhancing the page, not replacing it. For instance, don't use <button onclick="...">, use a normal <input type="submit"> and hook into the form's submit event. That way:
Bogtha Bogtha Bogtha
Comment removed based on user account deletion
Are you suggesting that it didn't occur to those who created XMLHttpRequest how it might be used?
I think it was far more a case of it taking a while for someone to make a compelling enough application using it for it to get public acceptance and attention from mainstream developers. And probably a bit of reluctance to go down that path until a large enough percentage of users had a browser that supported it to make it make economic sense to invest in the use of such techniques on a large scale.
Nobody calls XmlHttpRequest() directly anymore. It's too much work, and there are slight differences between browser implementations. Nowadays everyone is using a wrapper library. Prototype is a very common one (it's certainly my favorite) -- abstracts everything into a nice set of functions for you -- you just specify the HTTP call you want to make, and the function you want it to call when the data comes back (because, in case you're not already aware, XmlHttpRequest() returns its data asynchronously).
The other nice thing you can do with Prototype is to avoid XML parsing altogether by saying "ok, here's the URL I want you to call; it's going to return pre-rendered HTML, and when it does, I want you to stick it in this DIV over here; don't bother me about it" and you can do things like automatically update portions of your page without reloading. You can even have an automatically recurring update, which is very cool for things like tickers, clocks, etc. We used it in our AJAX webmail/calendar system and it really worked well.
Tired of FB/Google censorship? Visit UNCENSORED!
Bandwidth ain't _that_ cheap. A constant connection would be annoying to maintain in spotting wifi, electrical storms, etc.
I personally prefer web development because of the forced finite life of each state. That sort of back and forth makes data validation, cross-process security, and other things that many web developers ignore very easy to implement. You just have to quit thinking continuously (rimshot please!) and start thinking discretely.
One strike against AJAX is that search engines won't be able to see any of your 'dynamic' content. Sure, you can code around it by providing static links to the same content, but it's something to keep in mind.
Beyond the XMLHTTP Request object, which has been around for several years as a solution looking for a problem...
Outlook Web Access, genius. That's the problem Microsoft made it to solve.
Better question, do you really want to be at the server end of a slashdotting consisting of persistent connections?
Development using Visual Studio has little to do with being a man and alot to do with wanting to complete projects within a reasonable timeframe. As a former PHP-lifer turned Visual Studio lover, I can attest to the fact that Visual Studio WILL cut your time to release numbers significantly/
When I have a kid, I want to put him in one of those strollers for twins and then run around the mall looking frantic.
Hacks to keep a connection alive? Over TCP/IP, a connection based protocol?! No, really?!
I am not certain that it is time to update the HTTP spec so much as to come up with an
accompanying spec for connection based browser communication before microsoft does.
Something similar to xmlHTTPrequest, but something that can maintain a symmetrical
connection that HTTP is not designed for.
I dunno, maybe something vaguely like this: (and i stress vaguely)
<script type="text/javascript">
var server = new host ("192.168.2.3");
var state = "michigan";
host.connect();
host.send("query.php?capitalof="+state);
document.write(" The capital of "+state+" is "+host.recv()+"<br>" );
host.send("query.php?populationof="+state);
document.write(" The population of "+state+" is "+host.recv()+"<br>" );
host.close();
</script>
Non sequitur: Your facts are uncoordinated.
This is worse than half the stuff in my freshman comp class at community college. You don't even have to be a writer to improve this, just cut out half the words. Someone ought to introduce him to the technique of reading his writing out loud.
Take this gem of a paragraph:
Not only does every sentence sound horrible on its own, but the whole paragraph communicates nothing at all. Well I guess it claims that there are three ways to do AJAX, but that's a pretty useless little factoid if you're not going to say what they are.
I can't decide whether I'm embarassed for him or inspired to write a book of my own.
After reading through five pages it all ended at "var dom = new ActiveXObject(......"
No thanks, next book please.
"ATLAS is a cross-browser AJAX framework, and Visual Studio 2005 produces valid, meaningful XHTML."
More important, will the final product run on a non-Microsoft web server?