Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript innerHTML include php

Why doesn't my code work?

function _(x){
    return document.getElementById(x);
}

function friends(){
    _("right").innerHTML = '<?php include_once "friendlist.php";?>';
}

Result:

<!--?php include_once "friendlist.php";?-->

How can I fix it?

like image 241
User Avatar asked Mar 17 '23 13:03

User


2 Answers

you have to do like this

$(document).ready(function(){
  $("#your_id").click(function(){
    $("#your_div").load('friendlist.php');
  });
});
like image 122
Ayyanar G Avatar answered Apr 01 '23 11:04

Ayyanar G


use below code it will work

 <div id="right">
   <script>
      document.write('<?php echo include_once "include.php";?>');
   </script>
</div>

or i test below code also it will work

 <body>
     <div id ="right" >

     </div>
  </body>

  <script>
    function friends(){
     var x=document.getElementById("right");
     x.innerHTML = '<?php include_once "include.php";?>';
     }      
    friends();    
 </script>
like image 21
Nishit Maheta Avatar answered Apr 01 '23 13:04

Nishit Maheta