How to get the array from PHP to JAVASCRIPT through AJAX and JSON?

前端 未结 2 1048
夕颜
夕颜 2021-01-27 10:40

Can someone help me out? It seems like I get a string instead of an array. Once I pass the array, which is the result of a sql query, from PHP to Javascript through AJAX, I woul

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-27 11:21

    Use JSON.parse() to turn the string from PHP into an array.

    success: function(data) {
        var results = JSON.parse(data); // like this
        alert( data );
        //Here I would like to loop the array and get the values
    }
    

提交回复
热议问题