0

This is my PHP code

$cars = array("Volvo", "BMW", "Toyota"); 
echo $cars;

This is my JavaScript

function assign_dt() {
  var cars = xmlHttp.responseText;

    document.getElementById('des').innerHTML = cars;

}

I need the values, but they shows me like this "Array" on the output.

1 Answer 1

3

You need to convert the array to a string - use json_encode() for this:

$cars = array("Volvo", "BMW", "Toyota"); 
echo json_encode($cars);
Sign up to request clarification or add additional context in comments.

1 Comment

I added a bit of explanation to your answer. You should make your answers more clear by explaining why your code works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.