将HTML页面替换为通过AJAX检索的内容 [英] Replace HTML page with contents retrieved via AJAX
本文介绍了将HTML页面替换为通过AJAX检索的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个具有典型结构的HTML页面:
I have an HTML page with a typical structure:
<html>
<head>
<script src="..." ></script>
<style>...</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(data);
,没有成功。
Do you think it is possible ? I've already tried to give the html tag an id and doing $(id).replace(data);
with no success.
不要问我为什么,但这就是我需要的(我正在和一个特殊的mashup builder网站合作...这是一个很长的故事)。
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).
编辑:我忘了说接收的内容中的脚本必须执行,即使使用 ; script src =...>
。
EDIT : I forgot to say that scripts in the received content have to be executed, even external scripts included using <script src="...">
.
推荐答案
jQuery :
try this with jQuery:
$('body').load( url,[data],[callback] );
阅读更多 docs.jquery.com / Ajax / load
这篇关于将HTML页面替换为通过AJAX检索的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文