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

后端 未结 5 1372
执笔经年
执笔经年 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:10

    json_encode is definitely the way to go. jQuery even has built-in support for parsing JSON. You could use e.g.

    $.ajax({
        url: "",
        type: 'POST',
        data: form_data,
        dataType: 'json', // will automatically convert array to JavaScript
        success: function(array) {
            alert(array[0]); // alerts first string
        }
    });
    

提交回复
热议问题