PDA

View Full Version : Why Ajax ???



psilos
10-11-2006, 10:54 AM
I have just a silly question??
Why should someone use Ajax scripts?
What are the benefits from that?

For example if i want to load external files(html) in my main page,
why not to use iframes for example...
I'm new and want to learn Ajax but i should first find the reason:p

Thanx in advance...

mwinter
10-11-2006, 05:32 PM
Why should someone use Ajax scripts?

When it solves a specific problem better than any alternative. Yes, your question was rather open (and a touch vague). :)



What are the benefits from that?

It would vary based on how the technology was applied. It might reduce bandwidth requirements (though not usually by a great deal). It may reduce server processor usage by having to process less data. It may increase perceived responsiveness.

There are disadvantages, of course. The XMLHttpRequest object is not supported on all browsers, or in all versions of the browsers that do support it. Moreover, ActiveX restrictions may disable it in MSIE, and a lack of scripting support in any browser will do the same[1]. Furthermore, as data won't be available until the response has been received in full, the processing of that data will be delayed on the client (compare to incremental rendering of HTML).



For example if i want to load external files(html) in my main page,
why not to use iframes for example...

Inline frames have better support than AJAX, and should be a consideration. However, a better one would be to process the document on the server first, if necessary, and use links normally to reload the complete document.

Using AJAX to load complete portions of markup has its own problems. It's pretty much impossible to bookmark a location, navigation controls don't work, the browser history is useless, and search engines won't index the site unless an AJAX-less fallback is provided (but if it is, there's arguably no point in using AJAX, considering the other issues).



I'm new and want to learn Ajax but i should first find the reason:p

Good. :) Too many bandwagons about these days. Nice to see people not jumping on to them.

Mike


[1] The implications of this is that for any critical functionality, a fallback is required. However, that applies to any scripted feature.

nelis
10-11-2006, 06:07 PM
AJAX also allows you to create more application style web pages..

google maps, gmail, meebo.. they utilize ajax. It allows you to update the page without actually refreshing it.

Though mwinter is correct about the downfalls. No history, or browser controls...

psilos
10-17-2006, 02:11 PM
Thanx for your answers...
I'll have in mind.

Keep up...

djr33
10-17-2006, 02:32 PM
A great example of something that needs ajax is an html-based chat. You need php/cgi/etc to access the database, and also need it to run in realtime. A constant refresh is annoying and wastes bandwidth. Using ajax, it can run in the background and be fairly seemless.

Ajax is overused for a lot of things that could easily be done with just javascript or another html alternative. So... don't overuse, but consider in the cases mentinoed above (and other similar ones).

ttnnkkrr
10-18-2006, 02:49 PM
as a semi experienced web site programmer there are some pro cons

Pros

Ajax returns the entire html of the page requested as a string makign it easily manipulated with a variety of languages before ever being displayed

allows you to create custom applications with no need to format out put formatting can be performed on the page that displays the result

allows you to ask a browser to search multiple pages return content as string then search strings for requested data without actually requireing the page to load (good for search this site options)

Cons

Browser support dispite it being 6 years old now the http request is barely supported
relative urls in documents yeild broken information such as images not displaying browser scripts on pages not working correctly and hyperlinks that do not have full url not working
can sometimes be slower for the user because entire page must be returned before any code or display can be executed on it


the point is there are really good reasons and times to use it and there are other times when it would be more a headache than a help

thats my spin on the subject

blm126
10-18-2006, 09:33 PM
Ajax returns the entire html of the page requested as a string makign it easily manipulated with a variety of languages before ever being displayed

The same can be said of a regular page. This has nothing to do with AJAX.


allows you to create custom applications with no need to format out put formatting can be performed on the page that displays the result
How is this an advantage(or a disavantage)? The formating could just as easily be returned by a new page request. Furthermore, if CSS is used this is never a problem.

allows you to ask a browser to search multiple pages return content as string then search strings for requested data without actually requireing the page to load (good for search this site options)
Wrong. Just plain wrong. If the browser is searching the text of each page, then they have downloaded the entire page. This requires the page to load, just not where the user can see it happening.


Browser support dispite it being 6 years old now the http request is barely supported
I don't see how this a problem. A regular backup should always be provided. Furthermore, XMLhttprequest has pretty decent browser support.

relative urls in documents yeild broken information such as images not displaying browser scripts on pages not working correctly and hyperlinks that do not have full url not working
Ok, I'll semi give you that point. This isn't always a problem, but can be.

can sometimes be slower for the user because entire page must be returned before any code or display can be executed on it
If you are loading the entire page then you have completely missed the point of AJAX.


the point is there are really good reasons and times to use it and there are other times when it would be more a headache than a help

I agree with that.

mwinter
10-19-2006, 12:42 PM
A great example of something that needs ajax is an html-based chat.

I wouldn't agree at all. HTTP is simply the wrong protocol for that sort of application. It would be better to use Java (an applet or Web Start application) to implement an IRC-like protocol, where a full-duplex, permanent connection can be established, eliminating the need to poll the server for more data.



A constant refresh is annoying and wastes bandwidth.

The constant refresh and wasted bandwidth is still there. Moreover, unless both sides play nice, there'll be closed and reopened connections occuring all the time, which wastes even more bandwidth and overloads the server.

Mike