微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – 何时使用iframe,ajax()或load()?

我知道多次询问iframe和ajax比较.但我想添加好的jQuery load()函数,并询问何时使用哪一个.

我确信他们都有自己的特定功能,所以我不想知道哪一个更快等等,我更想知道何时使用哪个从另一个页面检索数据?

<iframe>

load();

ajax();

解决方法

>何时使用iframe?

this answerManishearth

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.

  – 何时使用Ajax?

表格验证

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 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.

过滤数据

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.

调查和民意调查

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 as ajax over iframe with regard to cross domain
data
. You can use load when the result you are returning is html
and this provides option to render the result directly to the DOM
element

更新:

>何时使用AJAX

Basically,the main difference between ajax and load is that
ajax has more options that can be set before posting data to
server plus ajax can be used to store data in the server using
type="POST" and data returned from the server may be manipulated the
way we want unlike load which can be used only to render data.

总结一下 – 安全明智的ajax / load是好的,但如前所述,如果你知道使用iframe的安全漏洞,你可以采取必要的预防措施来防止它们.

AJAX USAGES AND DISADVANTAGES

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐