I get the response from php as:
{"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"}}
and want to display the errors:
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);
});
}
});
});
But it throws me TypeError: e is undefined
On older versions it works, but on 1.8.3 is not.
What I’m doing wrong?
My php code is:
$errors = $post->errors('');
$this->response->body(json_encode(array(
'success' => FALSE,
'errors' => $errors,
)));
$errors is associative array:
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"
)
Your
result.errorsis an array with just one element, the one you want to iterate with$.each, so just replace your following line:for this one:
that should do what you want.