开发者

Getting PHP array to JavaScript through Json

开发者 https://www.devze.com 2022-12-11 15:09 出处:网络
Hey, I\'ve got a PHP file that that echo\'s an array that has been encoded with json_encode. This file is used by the jQuery ajax function to retrieve the array. I am unable to figure out how to use t

Hey, I've got a PHP file that that echo's an array that has been encoded with json_encode. This file is used by the jQuery ajax function to retrieve the array. I am unable to figure out how to use the array though, I have managed to alert variables but not arrays. Here is my code:

function sessionStatus(){
    $(document).ready(function(){
        $.ajax({type:"POST", url:scriptRoot+"sessionStatus.php", success:fu开发者_开发技巧nction(data){
                alert(data[0]);
            }
        });
    });
}


json_encode(array("data1","data2"));


$.getJSON("sessionStatus.php",function(data){
      alert(data[0]);
});

Should alert "data1"


you need to use

data.property as an object not like an array[property]

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号