简体   繁体   中英

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).

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.

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). Inside the CMS that does not yield anything (literally blank), but on my test html page (not within the CMS) it works just fine. 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

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

You should be able to do this with 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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