iframe 与 ajax [英] iframes vs ajax

查看:24
本文介绍了iframe 与 ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一些选项卡(例如 jquery 选项卡)并且我想在每个选项卡中动态加载一些页面,我可以通过两种方式做到这一点

Suppose i have some tabs (e.g. jquery tab) and I want to dynamically load some page in each tab, I can do that in two ways

  1. 使用jquery ajax tabs(基本上是用ajax数据填充div)或
  2. 每个标签都可以包含一个 iframe 和加载到其中的页面.

第一季度.我看不出两种对待用户的方法有什么区别,是吗?

Q1. I see no difference between two approaches to user, is there?

第二季度.我认为 iframe 方式更好,因为 iframe 可以加载任何页面,但有时将 ajax 数据加载到 div 中可能无法按预期工作.

Q2. I think iframe way is better because iframe can load any page but sometimes loading ajax data into div may not work as expected.

推荐答案

首先,在包含的页面(或 ajax 调用)中出现错误可能更适合使用 ajax 方法处理.使用 iframe,您只会在页面中间看到一个难看的 404 或 500 错误.但是使用 ajax,您可以检测错误并显示更用户友好的错误消息.

For one, having an error in an included page (or ajax call) is probably better to handle with the ajax approach. With iframes you'll just get an ugly 404 or 500 error in the middle of your page. But with ajax you can detect the error and display a more user-friendly error message.

这还取决于您加载到页面中的数据.如果您控制正在加载的 html,则可以避免或修复可能出现的任何显示问题.如果您需要加载超出您控制范围的页面,最好(或必须)使用 iframe.

It also depends on what data you're loading into your page. If you control the html being loaded in, you can avoid or fix any display issues that may arise. If you need to load a page outside of your control, iframes would be best (or necessary).

这两种方法也可能涉及可访问性问题,但我对此不够熟悉,无法确定哪种方法最适合屏幕阅读器等.

There may also be accessibility issues involved with either approach, but I'm not familiar enough with that to determine which approach works best with screen readers, etc.

这篇关于iframe 与 ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆