繁体   English   中英

从php传递json数组

[英]Pass json array from php

我没有花几个小时来寻找解决问题的方法,却找不到答案。

我正在同一页面上进行搜索,为此,我正在使用Jquery,AJAX和PHP。

来自php的数组仍然返回undefined。

PHP代码:

$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和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();
        });
    });

感谢您的帮助;)

在您的php文件中使用echo json_encode($array);

在你的jQuery中

 type: 'json',
method:'post'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM