Home Ask Login Register

Developers Planet

Your answer is one click away!

Imran Aslam February 2016

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

I call a jQuery function on link click and the function uses the post() method to call another page. I expect to see the rendered html result from other page but instead it shows me the html code of the other page.

        var albumid = $(this).siblings('input[name=albumid]').val();
            $.post("gallery-pics-temp.php", { albumid: albumid }, function(data) { 

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

    if (isset($_POST['albumid'])) {
        echo $_POST['albumid']; //just for checking if albumid is correct
        $openalbumid = $_POST['albumid'];
        include "config.php";
        //$openalbumid = $_GET['albumid'];
        $querypics = $con->prepare("select * from images where img_albumid='$openalbumid'");
        $resultpics = $querypics->fetchAll();

        $queryaname = $con->prepare("select * from albums where album_id='$openalbumid'");
        $resultaname = $queryaname->fetch();
        $aname = $resultaname['album_name']; 

    <div class="pics">
        <a href="/" style="float:left;line-height:50px;color:#fff;"> <<< Back </a>
        <h2 align="center" style="color:#fff;"><?php echo $aname; ?></h2>
        <hr />

        <?php foreach ($resultpics as $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;">  


Rory McCrossan February 2016

You need to use the html() method to add the retrieved data to the page, otherwise it gets encoded. Try this:


Vatsal February 2016

Use $('p#myid').html(data) instead It should work

Post Status

Asked in February 2016
Viewed 3,986 times
Voted 9
Answered 2 times


Leave an answer

Quote of the day: live life