getJSON没有使用新值更新div容器

时间:2016-01-17 07:20:06

标签: javascript jquery

我的JS没有更新我在HTML文档中指定的4个DIV容器的问题。我试图通过仔细检查JSON是否正确格式来诊断它,我已经验证了。我还仔细检查了API文档,以确保我遵循正确的语法。不确定是什么问题。

我使用的JQUERY版本是v2.1.4,附件是代码片段。

$(document).ready(function() {
  var ErrorVal = 'Error'

  $.getJSON('http://acweb.ddns.net',
    function(feeds) {
      //alert(feeds);
      var feedHTML = feeds.length;
      //var displayCounter = 1;

      var AllComplaintsCounter = 0;
      var PhoneComplaintsCounter = 0;
      var TVComplaintsCounter = 0;
      var InternetComplaintsCounter = 0;

      //for (var i=0; i<feeds.length; i++) {}

      $('#NewComplaints-Number').html(feedHTML);
      $('#PhoneComplaints-Number').html(feedHTML);
      $('#TVComplaints-Number').html(feedHTML);
      $('#NetworkComplaints-Number').html(feedHTML);

    }).fail(function(jqXHR, textStatus, errorThrown) {
    var error = "";
    if (jqXHR.status === 0) {
      error = 'Connection problem. Check file path and www vs non-www in getJSON request';
    } else if (jqXHR.status == 404) {
      error = 'Requested page not found. [404]';
    } else if (jqXHR.status == 500) {
      error = 'Internal Server Error [500].';
    } else if (exception === 'parsererror') {
      error = 'Requested JSON parse failed.';
    } else if (exception === 'timeout') {
      error = 'Time out error.';
    } else if (exception === 'abort') {
      error = 'Ajax request aborted.';
    } else {
      error = 'Uncaught Error.\n' + jqXHR.responseText;
    }

    $('#NewComplaints-Number').html(ErrorVal);
    $('#PhoneComplaints-Number').html(ErrorVal);
    $('#TVComplaints-Number').html(ErrorVal);
    $('#NetworkComplaints-Number').html(ErrorVal);
  });
});

0 个答案:

没有答案
相关问题