Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Jquery include problem


I want to change the value of php include() with jquery and this is how i did it.

$.post(\'page.php\', {
        include : id  //We set the id to be passed to the page here
    }, function(result){
    }, \'text\');
<div id="out_info">
<div><p><?php if(isset($_POST['include'])){ 
          include('../upload/info/' . $_POST['include'] . '.txt');} ?>
     <p><div id="emptyDiv"></div><p>

I get really strange problem. The emptyDiv gets filled with my html page code and doubles my page.

This sounds like more of a PHP problem than a JS issue. It sounds like you are making a request to page.php, which returns a full HTML page, which is probably how it is supposed to operate. If you just want a snippet of HTML code, you need to only output the code you need from your page.php, rather than an entire HTML page.

1 Answer

Casey Ydenberg
Casey Ydenberg
15,622 Points

You can't change PHP code (running on the server) with Javascript (running in the browser). You can only alter the document that is produced by that PHP code.