1
我有一個從html到/ html的完整html頁面,包括存儲在數據庫中的腳本標記,css等。我正在使用jquery從基於數據庫中的行的ID從另一個網站的PHP腳本獲取變量。 這一切都很完美,但BODY和HEAD標籤被刪除 - 其餘的html完好無損。任何人都可以對此有所瞭解嗎? 這裏是我的代碼:用jquery顯示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內容?爲什麼不只是更換需要更換的位? – lonesomeday
這個相關的問題看起來像它可能對你有用:http://stackoverflow.com/questions/1236360/replace-the-entire-html-node-using-jquery – Treborbob
你到底想要達到什麼目的?如果你想顯示整個HTML頁面,爲什麼不通過URL訪問它? –