Asynchronous Requests with JavaScript and Ajax
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."
Google of course!f -8&oe=utf-8&client=firefox-a&rls=org.mozilla:en-US :official/
_ source=AdWords&utm_campaign=us-ha-en-blogsearch&ut m_term=blogsearch&utm_medium=cpc&utm_content=googl eblogsearch&q=ajax&btnG=Search+Blogs/
http://www.google.com/search?q=ajax&start=0&ie=ut
http://blogsearch.google.com/blogsearch?hl=en&utm
GetTheJob.com : Nothing but Real Jobs.
"I rarely read an entire article about a single object"
And I never read something pointed to by such an uninterested observer.
This looks like the same AJAX "Hello World" I have read dozens of times before. Nothing new here.
??? Who did it ?
If you liked this article then you will surely like AJAX Developer's Journal , just launched digitally/online and replete with how-to articles and interviews, all freely available. It's edited by Rob Gonda.
While slightly off-topic, I do have to say that IBM's articles are some of the best on the net. They have very good writers and can explain things without resorting to techno-babble for the layman.
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?
Quality Hosting e3 Servers
I am sorry - i cannot believe how much hype there is over 'ajax'. This is something that has been going on for so long. In the past - we have done this using 1x1 frames and parsed the Xml with light Js libraries. I guess I must be getting old - I always sneered at the 'mainframers' that would complain and say 'that is nothing new - we have been doing that since 1876'. Now - I guess I see the same thing. A new marketing hype name - and the old technique is here
I hope that the next version of the web is much more than HTML pages that don't refresh with a full round trip. Really though - we did this at least 5 or 6 years ago..... I like google maps, Flickr and the others, but it is NOT a revolution. Someone innovate for real and show me a revolution if you want to justify the Ajax hype or the Web 2.0 hype!!!!
-Irate -
Chris
" I have no tag line. "
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 or Mochikit Javascript libraries/toolkits (others exist btw, those are just fairly stable and advanced), which actually:
Just wondering...
"The way we can tell it's C# instead of Haskell is because it's nine lines instead of two." -- wadler
Aren't we supposed to know that. This is Slashdot after all.
Next article: What is cmd.exe?
OK, here goes some /. nitpicking but it was a funny title: Asynchronous Requests with JavaScript and Ajax. Someone need a reminder of what Ajax is again (Asynchronous JavaScript And XML).
Beware: In C++, your friends can see your privates!
I have seen this article in different formats everywhere, however I still read them just to see if there is ever a new spin.
p -01-method-for-delivery-of.html
It seems to me that everyone is happy to send a text string in one direction and then they proclaim they are the champion. When the reality is you will saturate your server with http requests if you keep everything functioning on such an atomic scale that each request is for but one piece of info from the server.
I wrote a simple article that goes 1 step deeper and actually talks about shipping complex data types over one AJAX request and parsing at the client.
Take a read if this stuff is interesting to you:
http://therustednail.blogspot.com/2005/11/ajax-ti
Isn't it: 'AJAX: Asynchronous Requests for XML (and other things) from JavaScript'?
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...
that you may as well go with a library like CPaint http://cpaint.booleansystems.com/ . It saves a lot of time, and the principle of AJAX is so simple anyway you aren't really missing out on any 'under the hood' shananigans. CPaint combined with some of the JavaScript from Scriptaculous http://script.aculo.us/ means you can quickly knock up something impressive and responsive with a pretty user interface that will let you extort as much money as you like from any Venture Capitalist you can garner an appointment with!
The problem with slashdot is that most of its users were bullied and stuffed into lockers as kids!
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.
I challenge someone to come up with a good article on that!
J'aime mieux les méchants que les imbéciles, parce qu'ils se reposent. -- Alexandre Dumas
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 and its PHP analogue CAKE, and also the excellent perl framework Catalyst
Newsfollow.com
an article about exactly what I'm going to do at work tomorrow. Thanks, Slashdot, but no thanks.
My honest first impression was that ti was a spyware site, you know, the ones that look useful, but are really just there for the sake of serving ads?
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.
hilarious
If you're just communicating with other parts of your app instead of 3rd-party components, why use XML? Append a script tag to the document, using the DOM. Put as many GET request variables in the src attribute's URI as you need. Return JavaScript code from the server. Array initializers, object initializers, whatever. You can even put an onload handler on the script tag so you can execute code once the request has completed. This is what I do. There is reason to continually generate and parse XML here. It's just an extra unneeded step. No need to use XML unless you're dealing w/ 3rd-party components that expect it or you need to data that isn't easily packed into GET request variables.
...
There ya go :)
"Asynchronous Requests with JavaScript and Ajax"
AJAX means "Asynchronous JavaScript & XML", so if we'll be redundant, do it properly:
"Asynchronous Requests with JavaScript and XML and Ajax"
- From the department of redundancy department
Were you trying to be Insightful or Funny?
By all means a pretty site does not mean a good site, there's obviously great content you can find on minimalistic or ass-ugly pages- but is it just me or does for a site preaching the benefits of ajax, it's really disgusting-looking?
space is pretty cool.
If anyone wants a lightweight, simple, cross-platform AJAX objects they should check this out: http://prototype.conio.net/ The well-written javascript (prototype.js) library is the basis for many innovative opensource AJAX frameworks/libraries including: - Ruby on Rails (built-in support) - http://script.aculo.us/ - http://openrico.org/ - http://bennolan.com/behaviour/
Waitress: ...or Lobster Thermidor a Crevette with a mornay sauce served in a Provencale manner with shallots and aubergines garnished with truffle pate, brandy and with a fried egg on top and spam.
Wife: Have you got anything without spam?
Waitress: Well, there's spam egg sausage and spam, that's not got much spam in it.
Were that I say, pancakes?
This is how you use AJAX to create XMLHttpRequest instances.
The Story: http://namb.la/popular/
The Explanation: http://namb.la/popular/tech.html
[Fuck Beta]
o0t!
What kind of post is this? All about http request?
I believe we have finally encountered negative information. Read this and you will know quantitatively less than you did before coming here.
Laws are for people with no friends.
AJAX perhaps should have been labelled "AJA" or "A.J.", since AJAX is not limited to XML.
Parsing XML requires loading & execution of a parser and XML is computation intensive, so it is more efficient to restrict XML to those places where you must communicate with "otherworldly" apps (constructed by outside world). But you have many choices
A more cross-browser solution is to fall back to pulling content from an IFRAME (either a hidden one already on the page, or, preferrably, one created with the DOM) when XMLHttpRequest is not present (in either Microsoft's browser or others). It's pretty trivial to write a Javascript class that will do this.
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 or onsubmit events). I wrote a whole site this way. It degrades almost perfectly without Javascript support. Granted, that won't work for sites like Google maps (without a fundamental shift in how their UI is presented, anyway).
With JavaScript, the object that is returned by the newoperator is the return value of the constructor. Which means you can set/override pretty much any object/property with a pseudo-constructor that returns any arbitrary object (class).
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
It took me less than 50 milliseconds to realize that site wasn't good... it's full of advertisements and there is little teaching going on. If I visited an AJAX-resource website, I'd like to see some code as soon as possible.
Wow. I built a couple of apps back in June of 2005 with basically that same methodology! Thanks IBM and Slashdot! Oh and it was cross browser compatiable as well.
-Dipster
My understanding is that half of Europeans run with JavaScript disabled but I have no hard figure.
I am dismayed at the number of sites that use JavaScript when it is unnecessary (clicking on a link, etc.). Perhaps there is some explanation for this, some use in it, that someone else can please provide?
How are you supposed to read the articles when they're hidden by pop-over ads? I clicked on about a dozen, and they're all hidden by an ad titled "Learn from the AJAX Masters." Why go to the trouble of building a web site and creating content if you're going to intentionally make it unusable? Nice waste of time.
Suppose the ads were served with ajax. Then you could claim it as a (profitable) example.
/ \
\ / ASCII ribbon campaign for peace
x
/ \
http://www.aflax.org/
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.
MORTAR COMBAT!
I've found xajax to be very powerful and easy to use.
Yet another one of Sys-Con's online publications people should avoid for various reasons.
Redundant.
pretty usefull: https://addons.mozilla.org/extensions/moreinfo.php ?id=1843&application=firefox
/ 01/firebug.html for the tipp
"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
This is the follow up article to the one posted a month or two ago:
1 2/11/2327239
http://developers.slashdot.org/article.pl?sid=05/
I find it fascinating how this Ajax buzzword took of almost the instant some new economy web consultant wisecrack coined the term in his blog. The stuff Ajax stands for all had been done before but suddenly everybody acted as if there'd be something new.
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 another chance to mix up Java and JavaScript.
We suffer more in our imagination than in reality. - Seneca
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.
Java is the blue pill
Choose the red pill
The title reads "Asynchronous Requests with Javascript and Asynchronous Javascript and XML"
Apparently someone doesn't have a complete understanding of the whole 'acronym' concept
Besides this, Ajax primers are old news, people have moved on. I myself got Javascript Object Serialization to work, making storing javascript data absolutely trivial, much easier than mucking around with XML, thus essentially making the 'ajax' acronym obsolete.
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's done much programming with asychronous calls (aka threads) can tell you, making the call is the easy part -- it's coordinating the results that's hard. A simple real world example highlights "the sync problem".
The Sync Problem
Its a common client-side requirement to fetch a template containing static data along with dynamic data from a web service call, blend them into a single UI element, and then display that element in a portion of the user's currently displayed page. In this common case you've got two separate data sources meaning you have two separate calls whose results have to be blended only after both complete. When confronted with this reality most developers switch to making synchronous calls (taking advantage of XMLHTTPRequest's truly new feature to "cheat"). If you decide to hang in there and stay with the asynchronous call format that's great, but we've yet to see a single AJAX toolkit that offers you any kind of multiple-request coordination -- so you'll end up writing the synchronization logic yourself.
If you use TIBET its simple:
Since TIBET was built before you could "cheat" via XMLHTTPRequest it's been designed to support asychronous event coordination from the start. TIBET uses event signaling and a set of types based on the Workflow Management Coalition's petri-net models for workflow event coordination to handle event synchronization. Because it uses events rather than XMLHTTPRequest callbacks you can use the previous example's pattern to join responses from both the server and the user since interactions with the user are asynchronous as well.Seastead this.
I think everybody understand all of this, if somehow involved with software development.
This article is useless like 90% of the DeveloperWorks articles.
If your app requires JavaScript, then clearly, anyone who is logged as using your app WILL have JavaScript enabled.
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.
retrorocket.o not found, launch anyway?
haha loopback, forgot about that one
This extends the overridden XMLHttpRequest with methods to invoke server scripts with generalized get and post methods and easy-to-use form-based get and post methods.
Verbum caro factum est
Oh my - a slashdot Ajax articele! Oh wait, haven't we dont this before here? I mean, we have already talked about Ajax as a buzzword http://it.slashdot.org/article.pl?sid=05/05/24/159 211&from=rss as well as State-Of-The-Art Ajax-Office apps http://slashdot.org/article.pl?sid=05/09/29/000223 &from=rss we also got into Ajax on server load http://ask.slashdot.org/article.pl?sid=05/12/05/23 39256 - now why are we "getting back to basics" and talking about an entry-level IBM Ajax article that has year-old information on already well established techniques?
Horns are really just a broken halo.
Who the hell ever deals with the XMLHttpRequest object long-term over the course of real Ajax development? I simple wrote a few functions to deal with this in my toolkit, or I copy and paste from the last project, and bang, I'm done with XMLHttpRequest. I focus on the XML layer, application level coding, look and feel, database stuff... but I do not spend any real time on the XMLHttpRequest object. WTF is the big deal?
Horns are really just a broken halo.
Expanding the acronym AJAX, the title of the post would be:
Asynchronous Requests with JavaScript and Asynchronous JavaScript and XML.
Nice emphasis of the important elements.
AJAX????
I thought all the hubbub about that died down months ago. I mean, what is this, 2005?
Register the editry.
Why? Dude... ITS AJAX. BFG.
Don't get me wrong, AJAX is useful, I use it. But COME ON! A whole journal devoted to AJAX?
Next some one will create a following for binary logic, and tout it as the "Next Biggest Thing". Get real.
A little shameless self-promotion, since no one else is shy about pushing what they think is good :) ...
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
A more "real-world" example of using AJAX: a Struts-based chat app:
http://struts.sourceforge.net/ajaxchat
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 JSP taglib:
http://javawebparts.sourceforge.net/ (click on the Javadocs link and look at the javawebparts.taglib.ajaxtags package)
(Note that this AjaxTags is *NOT* the same as the project named AjaxTags that you may have heard of... this is an unfortunate naming conflict... this AjaxTags actually existed first, and this one is a subcomponent of the larger Java Web Parts project... it also has a very different focus than the other AjaxTags)
If a pion (n-) collides with a proton in the woods & noone is there to hear it, does lamdba decay into the source pa
Hi, In contrast to most Slashdot readers I found this article useful. Some of you forget that you are developing .Net and Java all the day, while there are also people like me that spend most time in C, Clusters, distributed file systems etc. The Article is very good, and I am already trying out "Web 2.0". It is one of the best tutorials I have read for a long time. The philosophy is: There are always Slashdot readers that are not updated in the J2EE world, and that like to read informative documentation on the subject.
They lost me as soon as I saw "Web 2.0" in large bold letters. For once, can we keep the marketing BS out of techincal articles? They're like sandpaper down the side of my face.
BeauHD. Worst editor since kdawson.
Ric Romero has started working for IBM now?
NZ Electronics Enthusiasts: Check out my Trade Me Listings
For me, the Web WITH javascript and cookies is a lonely, dysfunctional place. You developers need to get your heads out of the scripting sand and start coding for Internet users who turn off all of your disgusting scripting and other bugs.
The problem with enabling javascript or any kind of client-side scripting is the same problem as with cookies or Flash - once enabled, it is enabled globally, and the user can't prevent those technologies from being used against his interests.
... if the stupid ass web developers weren't using it to track users, or to bog-down their webpages with horrid flashing advertisements and blinking crap. Java script might be okay, if it wasn't such a damned security risk and burden on the client-side. Heck, even cookies might have an occasional good use or two - if the slavering web developers weren't wetting themselves all over in their haste to use cookies for tracking and other harms.
Flash might be okay
Yes, AJAX leads to (all of the above harms and more) which leads to unwanted tracking of users who simply want a fucking anonymous Internet experience, and thus ultimately leads to spam.
I don't care about all the groovy things Google is doing with Google Maps or some anticipated Microsoft-less web-based word processor, if enabling the technologies which will make Google Maps etc. work means I have also opened a door letting all of the other immoral web developers come howl at me with their devious garbage applications working against my interests. AJAX is like opening your door a crack to let a friend in, but 15 criminals then elbow their way in while the door is open. Who needs such garbage on the Internet?
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
You can't handle the truth.
One thing is noticeable that AJAX is useless if you try to fetch data from other domain,most probably you would get permission denied error. Alex of ajaxextended.com has written an awesome library which deals with this issue,and since he is not using builtin xmlhttp object,therefore you don`t need to create seprate instances for IE and Firefox.i have tried to create an AJAX based feedback form for my blog and it can be used on any website with zero installation,even on sites like geocities,one can experience it http://kadnan.blogspot.com/,by clicking CONTACT ME option,details are given at http://kadnan.blogspot.com/2006/01/customized-ajax -based-contact-form-for.html
Quoting a sentence out of a paragraph can do wonders, isn't it?
How do you describe a reporter knocking on your door, introducing herself or himself as a reporter and asking for an interview as harassment? Print and radio and TV journalists do it all the time. Why shouldn't online journalists be allowed to do this? You have a choice to grant or decline an interview. What does ethics have anything to do with professional reporting and journalism? What is "unethical" is to report the facts knowingly wrong. That's not professional journalism. It might be called irresponsible blogging. From what I read and decided (I checked the facts myself), there was nothing wrong with the story as long as it reported the facts.
Exactly what version of MSIE would reject "Microsoft.XMLHTTP"?
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( typeof window.XMLHttpRequest == "undefined" ) {
window.XMLHttpRequest = function() {
try {
return new ActiveXObject( "Microsoft.XMLHTTP" );
} catch( e ) {}
}
return undefined;
}
}
It's not like anyone uses any new functionality that weren't present in the older versions.
I've been trying to get XMLHTTPRequest via POST happening for the last hour or so with no luck. Anyone have any guides or examples?
I am not an AJAX expert or anything but...
ActiveX...cross-platform?
Firefox does not support ActiveX objects by default, right?
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.
This is a bit off topic, but what's the deal with tool and library names lately. At one time we had simple descriptive names for standard libraries like libm or "the math library".
If the current trends had been in place when C was invented, instead of using libc and libm, we'd be using C with "C boogleblargle 1.2.5.3a now with the Quintrix (tm)" (that is, printf in it's own library), "C wallawalla FileStreams 7.3.5.4" (stdio minus printf in it's own library), "C credenza plus plus plus 12.9.3.4" (that would be strcat), and the all important godlike (said in hushed tones) "C FroBozz 1.4.75.9A" (AKA the fabs() function that doesn't mysteriously throw an exception if you do fabs(0.0) ). These would come to be abreviated as BB with Quintrix, Cc+plus+, and CFB1.4.75.9A Failure to pronounce the bolded A would be a heresy of course. God forbid we forget to mention the Quintrix even on the 5th reference in the same paragraph.
Perhaps I exagerate a little.