通过AJAX检索内容替换HTML页面 [英] Replace HTML page with contents retrieved via AJAX
本文介绍了通过AJAX检索内容替换HTML页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个典型结构的HTML页面:
I have an HTML page with a typical structure:
<html>
<head>
<script .../>
<style .../>
</head>
<body>
content
</body>
<script>
var success_callback = function(data) {
// REPLACE PAGE CONTENT & STRUCTURE WITH "data"
}
ajax(url, params, success_callback);
</script>
</html>
你是否认为这是可能的吗?我已经试过给HTML标记的ID和做 $(ID).replace(数据);
没有成功
不要问我为什么,但是这正是我需要的(我正与一个特殊的混搭建设者网站...这是一个很长的故事)。
Don't ask me why, but that is what I need (I'm working with a special "mashup builder" site... it is a long story).
修改:我忘了说,在接收的内容脚本已经被执行,使用甚至包括外部脚本&LT;脚本SRC = ......&GT;
EDIT : I forgot to say that scripts in the received content have to be executed, even external scripts included using <script src="...">
.
推荐答案
尝试用的jQuery
$('body').load( url,[data],[callback] );
了解更多的 docs.jquery.com /阿贾克斯/负载
这篇关于通过AJAX检索内容替换HTML页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文