0

Having an issue where my JS is not updating 4 DIV containers I have specified in my HTML document. I have attempted to diagnose it by double checking the JSON is correct format, which I verified. I also double checked the API docs to ensure I was following the correct syntax. Not sure what the issue is.

JQUERY version I am using is v2.1.4, attached is the code snippet.

$(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);
  });
});
Jinyoung Kim
  • 1,885
  • 3
  • 14
  • 23
user2100493
  • 1,258
  • 4
  • 15
  • 26
  • `feeds.length` is undefined since it is an object not an array. – JRodDynamite Jan 17 '16 at 07:24
  • Is your script updating any of the div's? Either with a JSON result or error code? – Kurt Van den Branden Jan 17 '16 at 07:25
  • Cors enabled in your script? – mplungjan Jan 17 '16 at 07:27
  • If I change ErrorVal to error I get _Connection problem. Check file path and www vs non-www in getJSON request_ https://jsfiddle.net/mplungjan/nasnzug5/ - likely because I changed to https since I cannot run jsfiddle in mixed mode – mplungjan Jan 17 '16 at 07:34
  • added an htaccess file to my server directory to allow cross-domain. – user2100493 Jan 17 '16 at 08:00
  • 1
    I cannot get the CORS running: http://plungjan.name/SO/acweb.html `XMLHttpRequest cannot load http://acweb.ddns.net/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://plungjan.name' is therefore not allowed access.` – mplungjan Jan 17 '16 at 08:05
  • I added an .htaccess to the root of my php script which serves the JSON data above Header add Access-Control-Allow-Origin: * – user2100493 Jan 17 '16 at 08:16
  • Think i resolved the issue mplungjan, It seems ur link is no longer giver connection error – user2100493 Jan 17 '16 at 08:24
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/100876/discussion-between-user2100493-and-mplungjan). – user2100493 Jan 17 '16 at 08:27

0 Answers0