Chartjs-Chart.js, PHP and JSON loop issue

0👍

Try to add the dataType property to the object literal that is the argument of the ajax() function. As you are getting a JSON from PHP, the property should have "json" as its value.

$.ajax({
    url: "test.php",
    method: "GET",
    dataType: "json",
    success: function(data) {
         // ...
    },
    error: function(jqXHR, textStatus, errorThrown) {
      console.log("AJAX ERROR",textStatus,errorThrown,jqXHR);
    }
});

I tested with this PHP file.

test.php

<?php
  echo '[{"id":"1", "name":"John Doe", "count":"7"},{"id":"2", "name":"ABC", "count":"5"},{"id":"3", "name":"XYZ", "count":"29"}]';
?>

Leave a comment