我收到来自 PHP 的 ajax 响应。我想解码响应,并获取 3 个 URL
代码是 HTML/JS
<script type="text/javascript">
$(document).ready(function() {
$(".goButton").click(function() {
var dir = $(this).attr("id");
var imId = $(".theImage").attr("id");
$.ajax({
url: "viewnew.php",
data: {
current_image: imId,
direction : dir
},
success: function(ret) {
alert(ret);
$(".theImage").attr("src", ret);
if ('prev' == dir) {
imId ++;
} else {
imId --;
}
$("#theImage").attr("id", imId);
}
});
});
});
</script>
<body>
<img id="416" class="theImage" src="" />
<a href="#null" class="goButton" id="next">Next</a>
</body>
PHP文件是
$query = 'SELECT * FROM picture ORDER BY RANDOM() LIMIT 2';
$result = mysql_query($query);
$rec = mysql_fetch_array( $result, MYSQL_ASSOC );
echo $rec['pic_location'];
我还想获取下 3 张图像,以便在单击下一个按钮时显示这 2 张图像将全屏显示。一个将显示为全尺寸,另一个显示为缩略图。我如何解码来自 Ajax 的响应?