So How Do You Code an AJAX Web Page? 231
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.'"
Saving AJAX (Score:5, Insightful)
Huh (Score:5, Insightful)
Print version here. [computerworld.com]
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:
Comment removed (Score:4, Insightful)
Solution looking for a problem? (Score:3, Insightful)
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 (Score:5, Insightful)
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.
Re:HTTP, time to update? (Score:5, Insightful)
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.
AJAX and Search Engines (Score:2, Insightful)
Article writer looking for a brain (Score:1, Insightful)
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.
Re:HTTP, time to update? (Score:3, Insightful)
Re:So How Do You Code an AJAX Web Page? (Score:2, Insightful)
Re:HTTP, time to update? (Score:3, Insightful)
Re:Nobody calls XmlHttpRequest() directly anymore (Score:3, Insightful)
Well, for one thing, where you wrote 16 lines of code, doing the same thing in Prototype would have taken 1 line of code. Isn't that the point of wrapper libraries? To make repetitive, commonly used tasks like this one more convenient? (Not to mention, the 1-line Prototype call would also work in IE5 and FF1.0)
Re:Nobody calls XmlHttpRequest() directly anymore (Score:3, Insightful)
Re:HTTP, time to update? (Score:3, Insightful)
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>
Re:Both Repetitive and Redundant (Score:4, Insightful)
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.
next.... (Score:3, Insightful)
No thanks, next book please.
Re:Saving AJAX (Score:3, Insightful)
Where you get into trouble is when you start relying on non HTML "widgets" for controls that are drawn and managed by javascript rather than rendered by the server. I would tend to avoid this unless you have a framework that takes care of all the "state" information for you. Problem is that those frameworks can be pretty heavy and slow.
The biggest problem with sites that overutilize AJAX is that they are difficult to bookmark. Users often want to bookmark parts of a site or send URLs to friends. If all of your app/site resides in a single page/url, nobody can link into it. This can be a bonus for people who wnat to prevent deep linking, but I think most users benefit from deep linking.
What it comes down to is: It depends.
Do you have a particular language/framework/application in mind?
-matthew
Re:So How Do You Code an AJAX Web Page? (Score:2, Insightful)
More important, will the final product run on a non-Microsoft web server?