如何使用AJAX作为iframe的替代方案? [英] How can I use AJAX as an alternative to an iframe?

查看:132
本文介绍了如何使用AJAX作为iframe的替代方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我在网站上使用iframe来显示来自其他网页的内容,例如表单。我遇到的问题是在登录页面上,当用户使用iframe中的表单登录时,它只显示登录iframe中的下一页 - 这完全没用。

at the moment I am using iframes on my website to display content from other pages like forms. The problem I have, is on the login page, when the user logs in with a form inside an iframe, it just shows the next page inside the login iframe - which is completely useless.

我听说AJAX对于这样的事情更加灵活和动态,但我无法弄清楚如何使用它,我看了一些教程,但似乎没有在显示中那么远页面内的页面。

I have heard that AJAX is much more flexible and dynamic for things like this, but I can't work out how to use it, I have looked at some tutorials but don't seem to be getting that far in displaying a page inside a page.

如何用AJAX替换我的iframe?

How can I replace my iframe with AJAX?

提前感谢:)

推荐答案

由于您不会使用iFrame,因此您需要一个容器来放置您的页面。对于AJAX,通常的做法是使用< div> 元素来保存该数据。此外,jQuery或其他支持AJAX的Javascript库将通过使用经过测试的代码使您的生活更轻松,因此您可以专注于您的业务逻辑而不是细节。因此,在您的HTML中,您将需要一个容器元素:

Since you won't be using iFrames you will need a container to put your page into. With AJAX, it is common practice to use a <div> element to hold that data. Also, jQuery or another Javascript library supporting AJAX will make your life easier with working tested code so you can focus on your business logic rather than the nitty gritty. So, in your HTML, you will need a container element:

<div id="otherpage"></div>

然后在包含的javascript文件中,你可以使用这个jQuery:

Then in an included javascript file, you can use this jQuery:

$(document).ready(function() {
   $('#otherpage').load('otherpage.html', function() {
      alert('Load was performed.');
   });
});

当然,在使用之前,请确保包含jQuery。 本教程应该可以帮助您开始使用jQuery。

Of course, before using that, make sure you include jQuery as well. This tutorial should help you get started with jQuery.

这篇关于如何使用AJAX作为iframe的替代方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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