我在鏈接單擊時調用jQuery函數,該函數使用post()
方法調用另一個頁面。我期望看到從其他頁面呈現的HTML結果,但它顯示了其他頁面的HTML代碼。HTML代碼不能用於jquery調用,而是輸出HTML代碼
$(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);
});
});
});
其他頁面:(圖庫 - 圖片 - temp.php)
<?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'");
$querypics->execute();
$resultpics = $querypics->fetchAll();
$queryaname = $con->prepare("select * from albums where 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;"> <<< 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;">
</a>
</div>
<?php } ?>
</div>
<?php } ?>
@RoryMcCrossan沒有它給空頁,因爲在代碼庫的PIC-temp.php將在後期才起作用[「ALBUMID」] –