I am getting an ajax response from a PHP. I want to decode the response , and get the 3 URL’s
The code is 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>
And the PHP file is
$query = 'SELECT * FROM picture ORDER BY RANDOM() LIMIT 2';
$result = mysql_query($query);
$rec = mysql_fetch_array( $result, MYSQL_ASSOC );
echo $rec['pic_location'];
I want to get the next 3 image also so that i can show that these 2 images will come up in full screen when the next button is clicked. One will Appear as a full size and other as a thumbnail. How do i decode the response from the Ajax ?
Not tested, but I think it should work. (This code assumes PHP returns the
json_encode()‘ed array)