the problem is that the console.log('res', res)
shows that res.message is a valid string (IMO) but when shown in an alert, it shows undefined
. I also tried using typeof res.message
and it also returns undefined
.. why is that?
this is my code:
var myData = $('#myform').serializeArray();
$.ajax({
url: '/test/test1',
type: 'POST',
data: myData,
success: function(res) {
if (res.status) {
window.location.reload();
} else {
console.log('failed', res);
// the content of res is like so:
// {"status":"1", "message":"approval for \"Nominations\" was successful."}
alert(res.message);
}
},
error: function(err) {
console.log('error', err.responseText);
}
});