weixin_33701617 2016-11-07 12:21 采纳率: 0%
浏览 44

从php传递json数组

I wast some hours searching solutions for my issue and I couldn't find an answer.

I'm making a search on same page and for that, I'm using Jquery, AJAX and PHP.

The array from php still return undefined.

PHP code:

$i=0;        
while($eee = mysqli_fetch_array($result)) { 
    $array[$i][1] = $eee['ex'];
    $array[$i][2] = $eee['ex'];
    $array[$i][3] = $eee['ex'];
    $array[$i][4] = $eee['ex'];
    $array[$i][5] = $eee['ex'];
    $array[$i][6] = $eee['ex'];
    $array[$i][7] = $eee['ex'];
    $i = $i + 1;
}
json_encode($array)

AJAX and JQUERY

jQuery(document).ready(function(){
      $(document).on('submit', '#FormData', function(e) {
            $.ajax({
                url: $(this).attr('action'),
                type: $(this).attr('method'),
                data: $(this).serialize(),
                success: function(data) {
                    console.log(data[1]);
                }
            }); 
            e.preventDefault();
        });
    });

Thanks for any help here ;)

  • 写回答

1条回答 默认 最新

  • weixin_33691700 2016-11-07 12:27
    关注

    in your php file use echo json_encode($array);

    in your jquery

     type: 'json',
    method:'post'
    

    ,

    评论

报告相同问题?