A.Draug A.Draug - 1 year ago 40
Javascript Question

retrieve an array from a php encoded json and append it to a div body

I've been looking for hours and I can't find an answer to this.

I'm sending this array

$dailyHours = ['8:00','8:30','9:00','9:30','10:00','10:30','11:00','11:30','12:00','12:30','13:00','13:30','14:00','14:30'

endoded in a json using this code:

$list = array('hours' => $dailyHours);

$c = json_encode($list);

echo $c;

I want to display it on an html div. For that I'm using this code:

success: function(msg,string,jqXHR){


This doesn't work, and the error I'm getting is:

Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.

I'm guessing this doesn't work because I either can't encode it like that or I can't append it like that. Is there any way of doing this? Thanks

result of console.log(msg.hours)



msg.hours is an array and jQuery’s .html() method accepts a string as a parameter.

You should convert the array to string first by toString() method.

Try this: