How to pass an array using PHP & Ajax to Javascript?

后端 未结 5 1374
执笔经年
执笔经年 2020-12-03 07:33

Apologies if this explanation isn\'t clear, it\'s hard for me to understand too. How can I use PHP & Ajax to send an array to Javascript? I\'m using Aja

5条回答
  •  我在风中等你
    2020-12-03 08:33

    return the json itself and then construct the array in js by looping over the json as follows:

    var array=[];
    for(var key in json)
    {    
        if(json.hasOwnProperty(key))
          array.push(json[key]);
    }
    

    Or you can simply work with the json itself any reason for needing the array?

    something like json[0] or json[1] etc.

提交回复
热议问题