无法通过Jquery访问JSON长度属性

时间:2017-02-17 13:07:49

标签: javascript jquery html json iframe

我正在尝试用iframe标签上嵌入的不同PDF填充div,pdfs的src取自这个json文件:

    <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>   

这是整个jquery代码:

*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)*

我收到了这个错误:

SELECT origin_state,
        destination_state,
        SUM(package_weight) OVER (PARTITION BY origin_state, destination_state) AS pkgwgrbyorganddest,
        SUM(package_weight) OVER (PARTITION BY origin_state) AS pkgwgrbyorg,
        SUM(package_weight) OVER (PARTITION BY destination_state) AS pkgwgrbydest
 FROM shipping;

所以我猜测的是我的jquery的那部分无法访问json变量(Object.keys( json )。length)。任何帮助都会非常感激,我是一个关于如何在这种情况下处理json文件的新手。提前谢谢了。

0 个答案:

没有答案