通过ajax填充HTML文件 [英] fill div with html file via ajax

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

问题描述

我在我的主html文件上有一个div;

I have a div on my main html file;

<div id="content"></div>

和两个html文件:login.html& singup.html。

and two html files: login.html & singup.html.

导航条也出现在我的页面顶部。
单击登录按钮时,是否可以使用AJAX和登录文件的内容填充div的内容,并在点击注册按钮时用singup.html填充它?

Also a navigation bar is present on the top of my page. Is it possible to fill the content of the div with the use of AJAX with the content of the login file when the login button is clicked and fill it with singup.html when the register button is clicked?

以下是按钮:

these are the buttons:

<li><a href="#">Login</a></li>
<li><a href="#">Register</a></li>


推荐答案

获取 responeText 并设置 div.innerHTML = AJAX.responseText;

如果我的意思是包含< html>< head>< / head><< code> login.html ; body> ...< / body>< / html> 标记 - 您可能只想添加< body> 标签。您可以使用regexp来获取它:

If your login.html page built as a stand-alone page, I mean, contains <html><head></head><body>...</body></html> tags - you might want to add just the inner content of the <body> tag. You can use regexp to get it:

div.innerHTML = AJAX.responseText.replace( /<body>([\s\S]*)<\/body>/i , "$1" );

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

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