Utilizing AJAX
, I am fetching information from a specified URL.
var settings = {
"url": ".php",
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "application/json"
},
"data": JSON.stringify({"email":"mail","userid":"admin","type":"push","apikey":"apikey"}),
};
e.preventDefault();
$.ajax(settings).done(function (response) {
console.log(response);
alert(response);
});
$.ajax({
url: ".php",
type: "POST",
"headers": {
"Content-Type": "application/json"
},
"data": JSON.stringify({"email":"mail","userid":"admin","type":"push","apikey":"apikey"}),
error: function(error) {
console.log(error.responseText);
}
I then retrieve and handle data with the use of responseText
. When accessing error.responseText
, I receive data structured like so:
{
"status": 402,
"status_message": "Failed",
"OTP": "536960"
}
This data is in string format. Although it validates on a JSON formatter, issues arise when attempting to parse or access values such as error.responseText.OTP, resulting in errors like (json.Parse anonymous).
var ex = JSON.parse({"status":402,"status_message":"Failed","OTP":"536960"});
This is my attempt at parsing the data.