Reputation: 775
I know iframe and ajax comparisons have been asked many times. But I would like to add the good jQuery load()
function, and also ask when to use which one.
I am certain they all have their own specific features, so I don't wanna know which one is faster and so on, I am more eager to recognize when to use which to retrieve the data from another page?
<iframe>
load();
ajax();
Upvotes: 4
Views: 3366
Reputation: 29683
From this answer by Manishearth
Given that framing is deprecated, and
AJAX
has origin control,iframes
is pretty much the only way to embed another page into yours.GMail is made from
iframes
. The smooth UX of GMail (you can still use it when your internet connection breaks, smooth navigation without having to reload every time) comes from iframes. Again, this could be implemented in AJAX, but it's harder.On the other hand, issues with iframes (CSRF, clickjacking, etc) are well known to modern developers and they can take measures to avoid that.
- When to use Ajax?
Form validation
This is almost a no-brainer. It's so much nicer when the form tells you as you are typing if you've filled it out wrong or not. Having to go to the server and then return an error message is not only old, it's slow. Leave the server validation in the form, that's important for accessibility. But for those who can support Ajax, tell them right away.
Comments
Comments on blogs or even just articles are a great use of Ajax. Comments can change all the time, and especially when a commenter hits the comment button, it's nice to see the comment appear immediately on the page.
Filtering data
If you've got a large table with a lot of data in it, a nice application for Ajax is to add filters and sorters to the table. Getting your Web table to act more like Excel is really useful to people.
Surveys and polls
When you click on your vote, the poll would just switch to show you the results. And before you comment, About doesn't yet support Ajax on our polls - but it sure would be nice. Maybe we can give the About.com developers an "Ajax call" of our own.
As far as
load
is concerned, in my personal opinion, it is used to load documents into any element in DOM, but will have same disadvantages asajax
overiframe
with regard to cross domain data. You can use load when the result you are returning ishtml
and this provides option to render the result directly to theDOM
element
UPDATE:
Basically, the main difference between
ajax
andload
is thatajax
has moreoptions
that can be set before posting data toserver
plusajax
can be used to storedata
in the server usingtype="POST"
and data returned from the server may be manipulated the way we want unlike load which can be used only to render data.
To conclude - Security wise ajax/load
is good but as said before if you know the loopholes of security using iframe
you can take necessary precautions to prevent them too.
Upvotes: 2