0

I passed the array (this array is obtained from the database) from PHP to JS as a response to my ajax request from JS.

So my question is : How do I access the values of the array that I sent through AJAX from PHP inside JS?

PHP code:

while($temp = @mysqli_fetch_array($execute_query)){
    $items_list[] = $temp['item_name'];
  }
}
echo (json_encode($items_list));

PHP output:

["100% Whole Wheat Bread", "Almond Biscotti", "Almond Cake"]

JS code(used jQuery):

var items_name_list = [];
$.ajax({
          url : 'get_items_list.php',
          datatype : 'json',
          success : (data)=> {
            items_name_list.push(JSON.parse(data));
          },
          error : (e) => {console.log(e);}
        });

JS output(on console):

[] 0: (166) ["100% Whole Wheat Bread", "Almond Biscotti", "Almond Cake"] length: 1 proto: Array(0)

How do I access the value Almond Biscotti that is present inside the array 0:

(166) ["100% Whole Wheat Bread", "Almond Biscotti", "Almond Cake Specials"]**

Aref
  • 746
  • 10
  • 27
Rishi Njr
  • 13
  • 7

0 Answers0