I have come across thing which is bothering me. The code I made is as follows
var json='';
function displayThumbnails(list) {
json = list;
for(var i in list)
{
var image = $("<img class='item'>").attr("src", list[i].thumbnail);
$("#showThumbnails").append(image);
}
}
alert(json);
I would like to ask that variable json has a scope outside function also but the alert shows blank value.
When console.log(json) is inside the function result is displayed. Scope of json does not end after the function yet alert shows blank value. Why.?
On Public Demand :D
This is mainpage.php
<script>
$(document).ready(function() {
var jqxhr = $.get( "php/list.php", function() {
})
.done(function(data) {
var list = JSON.parse(data);
console.log(list);
displayThumbnails(list);
})
.fail(function() {
alert( "Oh Snap, Server Error.!!! Try Again" );
location.reload();
});
});
</script>