![](/img/trans.png)
[英]Javascript - populate a div with content from a hidden div using click buttons
[英]Using JavaScript to populate the content in a div
我嘗試了幾種方法,問題是我們的網站是在一個自定義構建的CMS中,不允許我們使用除HTML和一些JavaScript之外的任何東西(它非常挑剔)。
我需要做的是讓CMS中的頁面用外部php頁面的內容替換頁面上一個div的內容。
這是我目前使用的代碼:
<script type="text/javascript">
$.ajax({
url: "http://website.com/files/table.php",
success: function(response){
$("#budget").append(response);
}
});
</script>
<div id="budget"></div>
php頁面上唯一的內容是一個巨大的表格(內容從數據庫表中填充)。 在CMS內部不產生任何東西(字面上是空白的),但在我的測試html頁面(不在CMS中)它工作得很好。 有沒有人知道使用這些類型限制的任何其他可能的解決方案?
嘗試
$("#budget").load("http://website.com/files/table.php");
要么
table.php響應中的一個片段
$("#budget").load("http://website.com/files/table.php #fragment");
您應該可以使用jquery(http://jquery.com/)執行此操作
<script type='text/javascript'>
$.get("table.php", function (data) //gets the code behind the page
{
$("#budget").html(data); //places the data in the budget div
});
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.