[英]Extracting data from a web page and inserting into html code of another webpage
[英]Inserting html code from one page, into another html page
我對基於網絡的資料有點新,所以請耐心等待。
我的本地驅動器上有兩個html頁面。 Test1.html和test2.html。
我如何獲取test2.html的內容並將它們放入test1.html的主體?
我已經研究過使用w3IncludeHTML();
以及jQuery .load()
類的東西
Test1.html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<p id="text"></p>
<script type="text/javascript">
$('#text').load("test2.html");
</script>
</body>
</html>
Test2.html
<ul class='myclass'>
<li>test li one</li>
<li>test li two</li>
<li>test li three</li>
</ul>
根據我們的聊天:
http://chat.stackoverflow.com/rooms/131606/discussion-between-brandon-and-fred-ii
您需要以管理員身份運行它,因為這是Windows 7下的權限問題。
我會嘗試jquery / ajax方法:
Test1.html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<p id="text"></p>
</body>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$.ajax({
type:'post',
url:'get_file_contents.php',
data:'file=Test2',
success:function(content){
var content = $.trim(content);
$('#text').append(content);
}
});
</script>
</html>
這是“get_file_contents.php”的示例
<?php
$file=$_POST["file"].".html";
$file_content=file_get_contents($file);
echo $file_content;
?>
此示例假定:
希望對你有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.