Passing array through AJAX from php to javascript

前端 未结 3 1639
青春惊慌失措
青春惊慌失措 2021-01-20 02:26

I need to get an array generated from a script php. I have Latitude and Longitude for each user in a database. I take the values from the db with this code (file.php):

3条回答
  •  遥遥无期
    2021-01-20 02:51

    You need to convert the php array to json, try:

    echo json_encode($array);

    jQuery should be able to see it's json being returned and create a javascript object out of it automatically.

    $.post('./file.php', function(result)
    {    
         $.each(result, function()
         {
             console.log(this.Latitude + ":" + this.Longitude);
         });
    });
    

提交回复
热议问题