php - 从 PHP 响应返回数据?

标签 php jquery ajax

我的 AJAX 请求是这样的 -

    $.ajax({
        type: "POST",
        url: "ajax/feed-check.php",
        dataType: "json",       
        data: {
            server: server,
        },  
        complete: function(data) {
            console.log(data);
            $('.Agencies').html('<p>'+data[0]+'</p>');
        }           
    })

上面的返回和数组如下所示

[{"feed_name":"example.zip","feed_time":"2015-10-16 00:00:24","feed_size":"1222","back_office"
:"example4","agencyID":"example2"},{"feed_name":"example2.zip","feed_time":"2015-10-16 08:20:00","feed_size"
:"3145","back_office":"example1","agencyID":"aaa"}]
    "

当AJAX请求中的完整功能完成时,我如何获取数据我正在尝试这样做

        complete: function(data) {
            $('.Agencies').html('<p>'+data[0]+'</p>');
        }           

但是我变得不确定,有人可以告诉我哪里出了问题吗?我需要取出所有数据。

我的 PHP 脚本 -

        $whereArray = array(
            "$where",
            "=",
            $_POST['server'],
        );

        $andArray = array(); //- Blank 'AND' array so that the 'get' call below doesn't fail if no 'ANDs' are passed.
        $orArray = array(); //- Blank 'OR' array so that the 'get' call below doesn't fail if no 'ORs' are passed.
        $order = array();

        $agencyfeed = paddyDB::getInstance("paddy_ms")->get('feed_files', $whereArray, $andArray, $orArray, $order);

        //print_r ($agencyfeed->results());
        $feeds = [];
        foreach ($agencyfeed->results() as $key) {

            $feeds[] = $key;
            //$key = $feeds['feed_name'];

        }

        echo json_encode($feeds);

正在查看错误的文件,derp。已使用相关详细信息更新了帖子

谢谢。

最佳答案

试试这个:

complete: function(data) {
                $.each(data, function(i, member) 
                {
                    $(".Agencies").html('<p>'+data[i].feed_name+'</p>');
                })

            }

关于php - 从 PHP 响应返回数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33649317/

相关文章:

javascript - 如何使用 PHP 和 jQuery 将 (.OBJ) Blob 文件上传到服务器?

php - 如何检查 WordPress 中的缩略图?

jquery - 如何通过单击链接而不是提交按钮来发出 AJAX 请求

javascript - 在 Ajax 表单中设置 Google Analytics 事件

jquery - 有没有简单的方法可以获取 Bootstrap 4 中模态的数据

jquery - Fine Uploader - 在初始化时设置 netUploads

javascript - AJAX 触发两次成功

javascript - CodeIgniter 附加带有相对链接的 URI 段

php - Yii2 中的滚动寻呼机扩展

php - 使用 AJAX、PHP 和 MySQL 链式填充 HTML 选择框