为什么JQuery AJAX调用返回未定义的对象?

定居点

我对php服务器脚本进行了jquery ajax调用,但遇到一条错误消息,告诉我未定义返回的JSON类型的数据。那么,如何解决这个问题呢?这是jquery ajax调用:

    $.ajax({
                url: 'listWorkProcess.php',
                method: 'post',
                data: data,
                success: function(feedback){
                    $.parseJSON('feedback');
                    console.log(feedback);// loged correctly
                    alert(feedback.message);//here is the undefined message
                    $('#table').html(feedback.row_html);//this not executed Why?
                }   
            });//end of ajax
基山索拉提亚

试试这个AJAX代码:

在您的代码中,需要进行小的更改,此更改是在AJAX代码中包含“ dataType ='json'”,如下所示

$.ajax({
    url: 'listWorkProcess.php',
    dataType:"json",
    method: 'post',
    data: data,
    success: function(feedback){
        console.log(feedback);// loged correctly
        alert(feedback.message);//here is the undefined message
        $('#table').html(feedback.row_html);//this not executed Why?
    }   
});

这是获得响应的简单方法,它以jsonencode formate的形式在控制器中设置,只需将dataType:'json'赋予AJAX代码即可。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章