【发布时间】:2018-06-26 16:06:40
【问题描述】:
我发出一个 ajax 请求,并以 json 形式返回,但它每次都给我“语法错误:json 中位置 0 处的意外令牌 A”,我将在下面发布我的 ajax 代码,谢谢。
$.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] =>
)
再次感谢
【问题讨论】:
-
该错误意味着您在响应中返回的内容不是有效的 JSON。在控制台的网络选项卡中检查响应
-
@RoryMcCrossan 感谢您的快速回复,原因是 {"0":{"proc_cat_id":"4","0":"4","proc_cat_name":"集体诉讼 (343 )","1":"集体诉讼","dec_count":"343","2":"343"},"1":{"proc_cat_id":"2","0":"2", "proc_cat_name":"Action (323)","1":"Action","dec_count":"323","2":"323"}}
-
您能否编辑您的问题以包含 JSON 响应 {"0" ...
标签: php jquery json ajax syntax