简体   繁体   English

使用JavaScript填充div中的内容

[英]Using JavaScript to populate the content in a div

I've tried a few ways of doing this, the problem is our site is within a custom built CMS that won't allow us to use anything other than HTML and some JavaScript (it's very picky). 我尝试了几种方法,问题是我们的网站是在一个自定义构建的CMS中,不允许我们使用除HTML和一些JavaScript之外的任何东西(它非常挑剔)。

What I need to do is have a page within the CMS replace the content of one div on the page with the content of an outside php page. 我需要做的是让CMS中的页面用外部php页面的内容替换页面上一个div的内容。

Here's the code I'm currently using: 这是我目前使用的代码:

<script type="text/javascript">

$.ajax({
    url: "http://website.com/files/table.php",
    success: function(response){
        $("#budget").append(response);
    }
});

</script>


<div id="budget"></div>

The sole content on the php page is a huge table (content being populated from a DB table). php页面上唯一的内容是一个巨大的表格(内容从数据库表中填充)。 Inside the CMS that does not yield anything (literally blank), but on my test html page (not within the CMS) it works just fine. 在CMS内部不产生任何东西(字面上是空白的),但在我的测试html页面(不在CMS中)它工作得很好。 Does anyone know of any other possible solutions working with these types of restraints? 有没有人知道使用这些类型限制的任何其他可能的解决方案?

try 尝试

$("#budget").load("http://website.com/files/table.php");

or 要么

a fragment from the table.php response table.php响应中的一个片段

$("#budget").load("http://website.com/files/table.php #fragment");

You should be able to do this with jquery (http://jquery.com/) 您应该可以使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM