ajax,语法错误:json在位置0处出现意外令牌A

问题描述:

我发出ajax请求,并以json形式返回,但是每次都会给我语法错误:json在位置0处出现意外令牌A",我将在下面发布我的ajax代码,谢谢.

I make an ajax request, and returned in json form, but it gives me "syntax error: unexpected token A in json at position 0" every time, I will post my ajax code below, thanks.

$.ajax({
        url: "/report/get-judge-optionals", type:'GET', dataType:'json', cache:true,
        data: {
            inputRole: $(this).attr('data-role'),
            court: selected.data("court"),
            judge: selected.data('value'),
            master: fields.master,
            report_id: fields.report_id
        },
        success: function(data, textStatus, jqXHR) {

        },
        beforeSend: function(jqXHR) {},
        error: function(jqXHR, textStatus, errorThrown) {alert(errorThrown);},
        complete: function(jqXHR,status) {}
    });

控制器功能返回的是

Zend\View\Model\JsonModel Object
(
[captureTo:protected] => 
[jsonpCallback:protected] => 
[terminate:protected] => 1
[children:protected] => Array
    (
    )

[options:protected] => Array
    (
    )

[template:protected] => 
[variables:protected] => Array
    (
        [0] => Array
            (
                [proc_cat_id] => 4
                [0] => 4
                [proc_cat_name] => Class Action (343)
                [1] => Class Action
                [dec_count] => 343
                [2] => 343
            )

        [1] => Array
            (
                [proc_cat_id] => 2
                [0] => 2
                [proc_cat_name] => Action (323)
                [1] => Action
                [dec_count] => 323
                [2] => 323
            )


    )

[append:protected] => 
)

再次感谢

您似乎收到的响应是print_r输出,您应该使用

it looks like the response you're getting is a print_r output, you should use

echo json_encode($object)

另外,如果上述方法不起作用,我会寻找服务器脚本输出的UTF8-BOM字符

also, if the above does not work, I would look for UTF8-BOM characters outputted from you server scripts