Выставляется состояние успешности/неуспешности (ошибки) из PHP, например, так:
// выставим ошибку
$error = 0;
if ($error) {
$data = array('type' => 'error', 'message' => 'Ну не получилось! (принять новые порядки)');
header('HTTP/1.1 400 Bad Request');
header('Content-Type: application/json; charset=UTF-8');
die(json_encode($data)); // можно и не прерывать скрипт, и вместо die() исп. echo()
}
else { // ответим успешным сообщением
$data = array('type' => 'success', 'message' => 'Новые порядки установлены, приняты и сохранены ⚑');
echo (json_encode($data));
// die (json_encode(array('type' => 'success', 'message' => $this->input->post('earr'))));
}
а вот пример кода на JS, который "принимает" подобный ответ:
$.ajax({
data: data,
type: 'POST',
url: '/admin/update',
success: function(response, textStatus) {
//console.log('responce = ' , response);
floatmsgbox({ // например выводим всплыв окно - или исп. alert()
type: 'success',
text: JSON.parse(response).message
});
},
error: function(response, textStatus) {
//console.log('responce = ' , response);
//console.log('textStatus = ' , textStatus);
if (textStatus != 'abort') {
floatmsgbox({ // например выводим всплыв окно - или исп. alert()
type: 'error',
text: JSON.parse(response.responseText).message
});
}
}
});