0

With the use of this answer I appear to have got the passing of an array from one PHP file to another working with AJAX Javascript.

However, if I try to use the data at all, it comes back as "undefined".

Am I missing a step?

ajax.php:

<?php
  $letters = array('A','B','C');
  echo json_encode($letters);
?>

JS:

function loadDoc() {
        letters = new Array();
        $.ajax({
                url:"ajax.php",
                type:"POST",
                success:function(msg){
                        letters = msg;
                },
                dataType:"json"
        });
        document.getElementById("demo").innerHTML = letters[0];
  }

Ultimately I just want to have the array back in the format ['A', 'B', 'C'] for use with chart.js.

chivs688
  • 177
  • 1
  • 1
  • 10

0 Answers0