我从 php 得到的响应为:
{"success":false,"errors":{"category_id":"category id must not be empty","name":"name must not be empty","uri":"uri must not be empty","price":"price must not be empty","status":"status must not be empty"}}
并希望显示错误:
form.submit(function(ev) {
ev.preventDefault();
$('.help-inline').remove();
var data = $(this).serialize();
$.post($(this).attr('action'), {'data': data}, function(result) {
if (result.success == true) {
console.log('true');
} else {
$.each(result.errors, function(label, error) {
console.log(label+' '+error);
});
}
});
});
但它让我TypeError: e is undefined
在旧版本上它可以工作,但在 1.8.3 上则不行。我做错了什么?
我的PHP代码是:
$errors = $post->errors('');
$this->response->body(json_encode(array(
'success' => FALSE,
'errors' => $errors,
)));
$errors 是关联数组:
array(5) (
"category_id" => string(29) "category id must not be empty"
"name" => string(22) "name must not be empty"
"uri" => string(21) "uri must not be empty"
"price" => string(23) "price must not be empty"
"status" => string(24) "status must not be empty"
)