duankaolei2921 2018-05-19 05:54
浏览 74
已采纳

PHP数组由xmlHttp.responseText转换为JavaScript

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条回答 默认 最新

  • dst2007 2018-05-19 05:58
    关注

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

    $cars = array("Volvo", "BMW", "Toyota"); 
    echo json_encode($cars);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?