且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过 AJAX 和 jQuery 从 PHP 数组中获取数据

更新时间:2023-02-26 10:07:31

你不能从js访问数组(php数组)试试

you cannot access array (php array) from js try

<?php
$array = array(1,2,3,4,5,6);
echo json_encode($array);
?>

和js

$(document).ready( function() {
    $('#prev').click(function() {
        $.ajax({
            type: 'POST',
            url: 'ajax.php',
            data: 'id=testdata',
            dataType: 'json',
            cache: false,
            success: function(result) {
                $('#content1').html(result[0]);
            },
        });
    });
});