Asynchronous Requests with JavaScript and Ajax 178
An anonymous reader writes "I rarely read an entire article about a single object, especially one that is this simple. However, you will use this object over and over again in each page and application that you write that uses Ajax. This article shows you how to create XMLHttpRequest instances in a cross-browser way, construct and send requests, and respond to the server."
Hello world (Score:3, Insightful)
Re:Hello world (Score:1)
Re:Hello world (Score:1)
I didn't even entertain the idea of using it before it was cross browser. Therefore, every one of the dozens of examples are cross-browser.
Re:Hello world (Score:2)
Re:Hello world (Score:3, Interesting)
So, would anyone be able to tell me how to send something to a server using a single half-trip? It may be a part of a persistent connection, any eventual ack can be sent through a separate channel, I don't really care about bandwidth -- all that matters is the latency between the user's action and the time
Re:Hello world (Score:3, Interesting)
If you throw away a can, does it matter how long it takes to get to the recycling center?
try AFLAX? (Score:3, Informative)
poke around in those (excellent) libraries a bit, maybe you'll find more basic socket handling facilities that you are looking for.
maybe "web 3.0" is closer than we think. servers pushing data to web clients.
Re:Hello world (Score:2)
No Java, not Flash, no other crap. It still doesn't work on MSIE or Opera, but I can always fall back to terminally slow full http requests. These are way too slow for decent interactivity in many cases -- but I can claim it works and direct those who want it to work fluently to a decent browser
More seriously, I would prefer a cross-platform solution, but this is nice at least for some users.
Re:Hello world (Score:3, Insightful)
You can't be looking very carefully then. Practically all the Ajax tutorials I've seen make beginner mistakes. This one's special because it's actually decent code.
And who invented the XMLHttpRequest class ? (Score:1)
Re:And who invented the XMLHttpRequest class ? (Score:1, Informative)
btw. Funny seeing IBM criticizing the people who invented the damn thing in the first place of implementing it differently than others have chosen to reimplement it.
Re:And who invented the XMLHttpRequest class ? (Score:2)
But, looking back at the real history, there are a few reasons it didn't attract wider usage several years ago.
Something like XMLHttpRequest had been on the minds of many people for a few years. While we diddled around about how to do it in a general cross-platform way, Microsoft went ahead and added their idea of how it should work. Unfortunately, it was available in WinIE only, and they wrapped it up in their ActiveX framework, which mos
If you like this, try too AJAX Developer's Journal (Score:4, Informative)
Re:If you like this, try too AJAX Developer's Jour (Score:3, Interesting)
Re:If you like this, try too AJAX Developer's Jour (Score:2)
Re:If you like this, try too AJAX Developer's Jour (Score:3, Insightful)
Re:If you like this, try too AJAX Developer's Jour (Score:2)
Re:If you like this, try too AJAX Developer's Jour (Score:2)
And ads that proclaim James Garrett as "The Father of AJAX" cast doubt on the whole site. Seems the site is intended to drive overpriced conferences.
Re:No Thanks to AJAX Developer's Journal (Score:2)
Hmmm, thanks for the reminder. They are the ones that did the hatchet job on Pamela Jones of GrokLaw. I actually was scanning through the website above looking for a subscription to this "Ajax developer" this morning, couldn't find it (saw a reference to an AJAX article written by Maureen O'Gara - name was familiar, but I didn't remember why).
I was going to try again later. I guess not now. Thanks.
IBM articles; Security with Javascript (Score:2, Interesting)
On another note, it seems that the current flavor of the month is Ajax. However, this requires that javascript be enabled. Is anyone running into the problem of finding a lot of users are forgoing this technology because they have (or have been told by their company) to disable javascript for security concerns?
Re:IBM articles; Security with Javascript (Score:5, Interesting)
I usually consider that 10% of the users have javascript partially or fully disabled either because they use javascript-less browsers (rare) or because of security issues (corporate environments). The trick there is to develop your web application with the Progressive Enhancements [hesketh.com] philosophy in mind: build a layered, Javascript/AJAX is merely a client-side behavioural layer added on top of the content layer (pure HTML) and the style layer (CSS), it relies on both but shouldn't be necessary for the application itself to work. It's merely applying the good ol' layers separation on your client-side web pages.
Following the Progressive Enhancements "way" raises the chances that your websites will degrade fairly gracefully when the upper layers are not available (old browser, quirks, ...) without "shutting down" the whole site for the user (or lower the cost/pain of having them degrade gracefully).
Re:IBM articles; Security with Javascript (Score:5, Insightful)
I think users who are disabling JavaScript are already doing themselves more harm than good. There are some genuinely good dynamic interfaces out there, and compared to the time and bandwidth savings they'll get by using them properly, the time required to install FireFox or a popup/ad blocker is negligible.
At least for intranet and company sites, there's a genuine demand for functionality that it's impossible to expose without full Javascript support. Consider a drag-and-drop interface where customer orders appear on the left-hand side, and the line items can be organized into a grid of dates and production stations (a piece of machinery or a particular set of workers) via drag-and-drop. I have a working AJAX app that does this, but I can't think how such an application would be useful in the absence of JavaScript. It would require literally hundreds of pageloads and a metric ton of typing (remember: No Javascript = No Calendar Picker) to do any meaningful analysis and manipulation, and the very act of using it would destroy the user's workflow/concentration, rendering the application less useful than the scrawled paper notes it replaces.
This is the direction the web is moving. There are a lot of consumer applications that would benefit from taking a more dynamic approach, especially when you combine the intuitiveness of drag and drop with the live feedback made possible by XMLHTTPRequest. I think that coddling to users without JavaScript is holding them back, as well as creating a lot of useless "busy-work" for web designers and developers.
Jasin NataelRe:IBM articles; Security with Javascript (Score:2, Insightful)
If only this were true ...
The internal corporate sites I'm used have a pretty good chance of running only with I-stinking-E, using whatever demon-inspired lock-in technologies they are teaching to Microsoft "programmers" these days.
It really twists my guts in a knot. Then, I smile, and do what I have to to get the job done.
Re:IBM articles; Security with Javascript (Score:2)
A website should work without JavaScript - that's the whole point of a webstandards based approach to website design. If a site requires JavaScript to provide access to data, it is fundamentally broken.
Its amusing that AJAX is promoted as a means for making websites more usable, but surely this should not be at the cost of its accessibility?
Nothing wrong with building AJAX based applications, just make sure y
Re:IBM articles; Security with Javascript (Score:2)
That does suck. Even with a good API, it's too easy to just throw the kitchen sink into a constructor or header file instead of including file links as needed. I hadn't thought about all the unnecessary JavaScript that flies around the web and never gets run, or worse, executes but never does anything useful.
The current common practice is to write a header file and just include it inline for every page on the site; This means that the <head> contents can't ever be changed by the individual script.
Re:IBM articles; Security with Javascript (Score:2)
Re:IBM articles; Security with Javascript (Score:2)
And I'd add that, for all meanings and purposes, the Web (regardless of it's "versioning") is a wonderfully universal medium: thanks to a pair of assistive technologies, it's possible for blind, paralytics, deafs people, ... to access informations in a much easier, much pleasant way.
These assistive technologies don't always work well with some javascript stuff. Accessibility is important, and the baseline of accessibility is the base text-only medium, without all the bells and whistles but with the conten
Re:IBM articles; Security with Javascript (Score:1, Informative)
1% don't use IE, and all have javascript enabled.
So no, we have not run into the problem with people having javascript disabled.
Re:IBM articles; Security with Javascript (Score:3, Informative)
1% don't use IE, and all have javascript enabled.
So no, we have not run into the problem with people having javascript disabled.
You left out the most important detail - does your site require IE/Javascript? Because if I heard about your service, here's what I usually do:
1. Read article, which is usually regurgitated press material
2. Google for user experiences or reviews
3. See that your app requi
Re:IBM articles; Security with Javascript (Score:2)
It does require Javascript to use the application since we began logging.
Well THAT skews your results. (Score:3, Insightful)
Your logs won't show how many people wanted to use your app but didn't because they had JS turned off for whatever reason.
Re:Well THAT skews your results. (Score:2)
We found out that it was silly because noone had JS turned off. Therefore we made our app better by taking advantage of this fact.
Re:IBM articles; Security with Javascript (Score:2)
I am not "forgoing this technology" because of security concerns, I am getting pissed off because of sites that force me to have Javascript enabled when I don't want to:
Coming from "JS disabled, enabled if needed/useful", I usually have it enabled now but I don't want to.
Which means that I will likely show up in the logs as a "non IE, but JS enabled => no problem" user (I am referring here to another answer to your post).
My probl
Re:IBM articles; Security with Javascript (Score:2)
Flavor of the last 6 months, to be more exact.
However, this requires that javascript be enabled. Is anyone running into the problem of finding a lot of users are forgoing this technology because they have (or have been told by their company) to disable javascript for security concerns?
I rolled out some very serious Ajax apps to a large corporate hardware server producing customer, a LOT of executitives running Safari, XP IE, XP
Ajax is OLD, web 2.0 - please.... (Score:2, Insightful)
I hope that the next version of the web is much
Re:Ajax is OLD, web 2.0 - please.... (Score:1)
Yeah. I mean I understand your reluctance to embrace a tech that was able to be accomplished before (though I might suggest that using hidden iframes was a bit less elegant). However, what do we care about hype. I let it roll off me. I like using the XMLHttpRequest object ...and you can get creative in your web apps with it. To be honest, I think most devs just opted for a page reload most of the time before all these libs and such came around. So in terms of "something new"...well it is new in the r
Re:Ajax is OLD, web 2.0 - please.... (Score:2, Insightful)
Re:Ajax is OLD, web 2.0 - please.... (Score:2, Informative)
Here is a nice start: someone already posted this, but here it goes again: http://en.wikip [wikipedia.org]
Re:Ajax is OLD, web 2.0 - please.... (Score:2)
The first ever.... apart from Applets, Flash, ActiveX...
Now, web 2.0 is not about changing what the web represents, that much is already established. The web 2.0 is about improving usability and response time
Actually, the term 'web 2.0' is so vague it is meaningless. I am not sure anyone can clearly say what it is about.
Re:Ajax is OLD, web 2.0 - please.... (Score:2)
Applets, Flash and XUL and not platform dependent, and aren't large.
For an instance, flash or java wouldn't let one use the simple "back" button of his browser.
Neither does AJAX. You don't get back to the previous page state that way. Many users find this confusing.
Those technologies are much more of a glue then a real solution.
It is the other way around - the web page was a glu
Re:Ajax is OLD, web 2.0 - please.... (Score:2)
I do this routinely - on MacOS/X, Windows and Linux. No problems at all.
A typical flash swf has more then 100kb. Compare that to a 1kb ajax code and tell me what is large...
Sorry, I don't get the point. Firstly 100kb is totally insignificant on modern machines. Secondly, 100kb of flash won't look small compared to 100kb of AJAX, and the way things are going, that won't take long to appear!
You can name it wha
Yeah, new news indeed (Score:5, Informative)
I mean, the first articles explaining how to create cross-browsers XMLHTTP requests ain't have more than a pair of years anyway...
Wouldn't it be slightly more interresting if Slashdot promoted useful stuff such as the Dojo [dojotoolkit.org] or Mochikit [mochikit.com] Javascript libraries/toolkits (others exist btw, those are just fairly stable and advanced), which actually:
Just wondering...
Re:Yeah, new news indeed (Score:4, Informative)
http://qooxdoo.oss.schlund.de/ [schlund.de]
Re:Yeah, new news indeed (Score:2)
Looks like desktop-UI emulation in web pages, which is not the goal of Dojo, Mochikit or Prototype.
Interresting nonetheless, so it's been bookmarked anyway.
Funny title (Score:5, Funny)
Re:Funny title (Score:5, Funny)
Re:Funny title (Score:2)
Re:Funny title (Score:2, Insightful)
Not to mention that it doesn't actually deal with XML, so it is not Ajax - it is just Asynchronous Requests with JavaScript. Can you say "buzzword applied without understanding or meaning"?
Re:Funny title (Score:2, Funny)
Damn commies.
-volve
Re:Funny title (Score:2)
"with JavaScript and Ajax"? (Score:2)
Seriously, Sunday's a slow news day and chance for a slower-paced review, but this acronym was thrown around all last year - it's a bit late for a one-liner from some anonymous who doesn't even understand what he's talking about...
Implementing AJAX is so uniform (Score:2)
What to do with XML results? (Score:5, Informative)
Bah. That's easy. The business of creating and using an XMLHttpRequest is well-documented and easy to do. What is far less well documented is how to access the resulting XML as a cross-browser XML DOM object. (Accessing it as text is easy.)
How does one access the results 1) as an XML DOM, and 2) in a cross browser way. I am currently investigating Sarissa [sourceforge.net].
I challenge someone to come up with a good article on that!
Sarissa tutorial (Score:3, Informative)
Re:What to do with XML results? (Score:5, Insightful)
Re:What to do with XML results? (Score:2)
It's not covered in many Ajax tutorials because manipulating XML with the DOM is the same as manipulating HTML with the DOM. Any DOM tutorial will suffice.
Re:What to do with XML results? (Score:2)
Easier than the article (Score:5, Informative)
I guess you can use JSON, and XML data formats with prototype, but I just use plain old text to accomplish whatever I want.
Prototype is also used in Ruby on Rails [rubyonrails.com] and its PHP analogue CAKE [cakephp.org], and also the excellent perl framework Catalyst [perl.org]
Is Ajax all win-win (Score:1)
I sincerely want to understand if there are any pitfalls. Is Ajax win-win for all of us? are there any security or any other concerns? What could be an argument against Ajax?
TIA for your answers.
Re:Is Ajax all win-win (Score:2)
- it doesn't work the way the web is designed, as page->page->page, which can create problems. You can't page-page
- you have to be very careful if you ajax app is making changes to the DB, not just reading
- 'win-win' doesn't really fit. It's another tool, and like any tool it can be used in the wrong place. The risk is that as 'the' thing, it's going to be used everywhere, even a lot of places where it really doesn't make sense. Kind of like companies putting dumb Flas
Re:Is Ajax all win-win (Score:1)
Re:Is Ajax all win-win (Score:2)
Ajax is as accessible as any other form of Javascript - it's accessible if done properly, but there's a lot of people who either don't bother or don't know how.
The way the web is designed is precisely what causes one of the problems that Ajax solves. There are many tasks for which going from one page to another simply doesn't make sense. If I have a list of things and
Re:Is Ajax all win-win (Score:2)
True- perhaps it's just a new level of required understanding. Most of the web still hasn't caught up with really making things ADA. The people who make Web 1.0 sites ADA will probably make Web 2.0 sites complient as well- at least in as much as it makes sense. It doesn't make a lot of sense for google maps.
I recently saw a page that had a graphic with the company contact info in it (address, phone etc) and the alt tag was "Company Contact Info Image".
XML isn't really needed. (Score:1)
Re:XML isn't really needed. (Score:2)
Re:XML isn't really needed. (Score:1)
Re:XML isn't really needed. (Score:2)
Re:XML isn't really needed. (Score:2, Insightful)
I just _said_ that the XML isn't useful _unless_ you need/want communication with 3rd-party components that use XML.
Plus, you also seem to be hinting that one should always aspire to connect their app up to 3rd-party components or even that one should always do the work to make the app integratable w/ XML before even knowing that this is necessary or required.
I'm sorry, but this is just another example of
Re:XML isn't really needed. (Score:2)
Re:XML isn't really needed. (Score:2)
Re:XML isn't really needed. (Score:2)
Re:XML isn't really needed. (Score:2)
I disagree. If you're supplying data, i.e. something not human readable, over the HTTP stack, you're providing services - albeit more RESTful than SOAP-oriented ones...
Before we drift too far, I'm not saying that one should always use XML (in fact, if you look at my first reply in this article [slashdot.org], you'll see that I brought up the point that AJAX doesn't have to imply XML before you did), but if there's any chance that your
Re:XML isn't really needed. (Score:2)
Because XMLhttprequest.open returns a DOM tree object. There's no other reason really.
Much simpler/better cross platform Ajax Objects... (Score:1)
I don't like spam! (Score:1, Offtopic)
Wife: Have you got anything without spam?
Waitress: Well, there's spam egg sausage and spam, that's not got much spam in it.
Re:I don't like spam! (Score:2)
Samy is my Hero (Score:2)
The Story: http://namb.la/popular/ [namb.la]
The Explanation: http://namb.la/popular/tech.html [namb.la]
Oh so rare, so rare (Score:1)
I believe we have finally encountered negative information. Read this and you will know quantitatively less than you did before coming here.
This is the usual way to do AJAX (Score:2)
For that matter, the most cross-browser solution is to default to using normal page requests when Javascript is unavailable (by defaulting to those actions and using JS to intercept them in the onclick o
overriding the constructor (Score:5, Informative)
Adding XMLHttpRequest to Internet Explorer:
if( typeof window.XMLHttpRequest == "undefined" ) {
window.XMLHttpRequest = function() {
var types = [
"Microsoft.XMLHTTP",
"MSXML2.XMLHTTP.5.0",
"MSXML2.XMLHTTP.4.0",
"MSXML2.XMLHTTP.3.0",
"MSXML2.XMLHTTP"
];
for( var i = 0; i < types.length; i++ ) {
try {
return new ActiveXObject( types[ i ] );
} catch( e ) {}
}
return undefined;
}
}
y
Better wrapping, same voodoo code (Score:2)
Would those versions have any hope of understanding any of the "MSXML2.*" names?
I keep seeing the same voodoo everywhere ajax is found, and conscientious voodoo priests like the author of the code in parent post make a point to list not 2, but 5 possible names.
In my testing, it seems every version of MS' XMLHttpRequest object is linked to the "Microsoft.XMLHTTP" name, so there's no reason to ever want something more complicated than this:
if( type
Re:overriding the constructor (Score:2)
http://www.livejournal.com/js/core.js [livejournal.com]
Re:overriding the constructor (Score:2)
Old news is Still old News (Score:2)
Firefox AJAX Debugger (Score:5, Informative)
"FireBug is a new tool that aids with debugging Javascript, DHTML, and Ajax. It is like a combination of the Javascript Console, DOM Inspector, and a command line Javascript interpreter."
thanks http://weblogs.mozillazine.org/gerv/archives/2006
For those that missed it... (Score:2, Informative)
http://developers.slashdot.org/article.pl?sid=05/
Fascinating (Score:2)
It's even admitted by it's 'creators' that the term Ajax is a buzzword. Being in the business of web conltant wisecracking myself I actually find it very usefull. From now on there is no chance whatsoever customers, clients and partners I talk to will get an
The Irony... The Irony... (Score:2, Informative)
Ironically, the real value in XMLHTTPRequest isn't that communication can be asynchronous. Form submissions, the previous way of handling server communication, were and still are asynchronous. XMLHTTPRequest actually makes it possible to support _synchronous_ calls and provides a single unified way to make either type of call.
Most writings on AJAX would have you believe that's enough -- make an asynchronous call, get an AJAX application. Unfortunately, as anyone who'
Re:The Irony... The Irony... (Score:2)
Way before this all was called Ajax I used the following simple method:
If you dont understand all of this.... (Score:2, Insightful)
I think everybody understand all of this, if somehow involved with software development.
This article is useless like 90% of the DeveloperWorks
Re:If you dont understand all of this.... (Score:2)
The author of this article obviously doesn't know how XMLHttpRequest works if they think that the remote we
Another Ajax Article? (Score:2)
WTF is the big deal? (Score:2)
Everyone else plugs theirs, so here's mine... (Score:2)
Another nice introductory article to AJAX, including a working example webapp of a using AJAX with a Struts-based application:
http://www.omnytex.com/articles [omnytex.com]
A more "real-world" example of using AJAX: a Struts-based chat app:
http://struts.sourceforge.net/ajaxchat [sourceforge.net]
The AjaxTags component of Java Web Parts, which allows you to add AJAX functions to a page in a purely declarative way using a extremely simple JS
Ugh (Score:3, Insightful)
So I guess (Score:2)
AJA? (Score:3, Informative)
Just last Friday I had to use AJAX but without XML at work. Instead of XML, it is much easier to just do this:
[["key1","value1"],["key2","value2"],["key3","val
Re:AJA? (Score:2)
Re:AJAX, I love it (Score:2)
Were you trying to be Insightful or Funny?
Re:What's next? (Score:2)