I'm trying to fill divs with different PDF's embedded on iframe tags, the src of the pdfs are taken from this json file:
{
"0" : {
"ID": "Doc1",
"URL":"http://192.168.13.158/31818_E-(1).PDF"
},
"1" : {
"ID": "Doc1",
"URL":"http://192.168.13.158/31818_P-(1).pdf"
},
"2" : {
"ID": "Doc1",
"URL":"http://192.168.13.158/31818_P-(2)%20(1).pdf"
},
"3" : {
"ID": "Doc1",
"URL":"http://192.168.13.158/31818_T-(1).pdf"
},
This is the whole jquery code:
<script>
$( document ).ready(function() {
var json = (function() {
json = null;
$.ajax({
'async': false,
'global': false,
'url': "planos.json",
'dataType': "json",
'success': function (data) {
json = data;
}
});
return json;
})();
/*Add Read Document Marker + PDF Reader*/
$(".panel-title .document-link").click(function(e) {
for (var i = 0; i < Object.keys(json).length; i++){
var dataOrderSelected=$(this).attr('data-order');
if ( (dataOrderSelected == i) && ($("iframe[data-order='"+dataOrderSelected+"']").attr("src","")))
{
$("iframe[data-order='"+dataOrderSelected+"']").attr('src', json[i].URL);
}
};
});
/*Add Read Document Marker + PDF Reader*/
});
</script>
I'm getting this error:
*Uncaught TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at HTMLAnchorElement.<anonymous> (audits-paso-2-tabs.html:423)
at HTMLAnchorElement.dispatch (jquery.min.js:5)
at HTMLAnchorElement.v.handle (jquery.min.js:5)*
So what i'm guessing is that that part of my jquery can't access the json variable (Object.keys(json).length). Any help would be really appreciate, im a newbie regarding how to deal with json files on this context. Many Thanks in advance.