Having trouble passing a parameter to the class for handling AJAX errors. The initial function is as follows:
function GetLastChangePass(UserId) {
var field =
{
id: UserId,
}
var fieldStringified = JSON.stringify(field)
$.ajax({
url: "/Users/LastChangePass",
method: 'PUT',
data: fieldStringified,
contentType: 'application/json; charset=utf-8',
success: (result) => {
if (result.includes('12.12.2000')) {
document.querySelector('#user-tslog').append('')
} else if (result == 'Not_tslog') {
document.querySelector('#user-tslog').append('')
}
else {
document.querySelector('#user-tslog').append(result)
}
},
error: (result) => {
addNewMessage("error", "Error")
console.error("fail responseText: " + result.responseText)
console.error("fail contentstatusText : " + result.statusText)
console.error("fail status TEST: " + result.status)
}
});
}
Created a class that takes the result of the AJAX call like below:
class ErrorConsole {
constructor(result) {
this.result = result
}
error() {
console.error("fail responseText: " + this.result.responseText)
console.error("fail contentstatusText : " + this.result.statusText)
console.error("fail status : " + this.result.status)
}
}
The issue arises when trying to pass the parameter using the updated function:
error: (result) => {
console.log(result) //===> there is object
addNewMessage("error", "Error");
err.error(result) //===> there is indefined
console.error("fail responseText: " + result.responseText)
console.error("fail contentstatusText : " + result.statusText)
console.error("fail status TEST: " + result.status)
}