【发布时间】:2011-07-04 16:00:01
【问题描述】:
我有一个从 html 到 /html 的整个 html 页面,包括脚本标签、css 等,存储在数据库中。我正在使用 jquery 根据来自另一个网站的数据库中行的 id 从 php 脚本中获取变量。 这一切都完美无缺,但删除了 BODY 和 HEAD 标签 - html 的其余部分完好无损。任何人都可以对此有所了解吗? 这是我的代码:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
function getListing(postid){
$.ajax({
type: "POST",
url: "http://my-website.com/url.php",
data: postid,
dataType: "html",
cache: false,
success: function(html) {
$("html").html(html);
}
});
}
getListing("postid=6943");
});
</script>
而且 php 非常基础:
<?php header("Access-Control-Allow-Origin: *");?>
<? if($_POST['postid']) {
$postid = $_POST['postid'];
// get html into a variable here *(code romved)*
echo $html;
}
?>
【问题讨论】:
-
我认为您可能错过了 AJAX 的重点...您为什么要替换整个 HTML 内容?为什么不直接更换需要更换的位?
-
这个相关问题看起来可能对您有用:stackoverflow.com/questions/1236360/…
-
您到底想达到什么目的?如果你想显示整个 HTML 页面,为什么不通过 URL 访问呢?
-
感谢 Treborbob .. 有效。 maenu,我想只使用脚本标签在另一个 URL 上生成页面。
-
它适用于除 IE 之外的所有浏览器.. sigh