javascript - HTML code not working on jquery call, instead it outputs HTML code -


i call jquery function on link click , function uses post() method call page. expect see rendered html result other page instead shows me html code of other page.

$(document).ready(function(){     $('a.thumbnail').click(function(){         $("div.albums").hide();         $("div.pics").show();         var albumid = $(this).siblings('input[name=albumid]').val();             $.post("gallery-pics-temp.php", { albumid: albumid }, function(data) {                  $('p#myid').text(data);             });         });     }); 

the other page: (gallery-pics-temp.php)

<?php      if (isset($_post['albumid'])) {         echo $_post['albumid']; //just checking if albumid correct         $openalbumid = $_post['albumid'];         include "config.php";         //$openalbumid = $_get['albumid'];         $querypics = $con->prepare("select * images img_albumid='$openalbumid'");         $querypics->execute();         $resultpics = $querypics->fetchall();          $queryaname = $con->prepare("select * albums album_id='$openalbumid'");         $queryaname->execute();         $resultaname = $queryaname->fetch();         $aname = $resultaname['album_name'];      ?>      <div class="pics">         <a href="/" style="float:left;line-height:50px;color:#fff;"> <<< </a>         <h2 align="center" style="color:#fff;"><?php echo $aname; ?></h2>         <hr />          <?php foreach ($resultpics $row1){ ?>             <div class="col-md-2">                 <a href="#" class="thumbnail" onclick="showimg(<?php echo $row1['img_id']; ?>)">                     <img src="<?php echo $row1['img_path'];?>/<?php echo $row1['img_id']; ?>.jpg" alt="pulpit rock" style="width:200px;height:150px;">                   </a>             </div>           <?php } ?>     </div> <?php } ?> 

you need use html() method add retrieved data page, otherwise gets encoded. try this:

$('p#myid').html(data); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -