Answer the question
In order to leave comments, you need to log in
How to handle Undefined in JSON (Ajax jquery)?
Hello! This problem haunts me for what a sleepless night I've lost count of:
There is a JSON code for processing the response, everything is classic:
function result(data){
if(data != null){
api_loan_amount = data.noticeInfo.document; // Сумма займа
api_expirationDate = data.applSubmissionCloseTime; // Дата окончания приема заявок
} else {
}
}
if(typeof data.noticeInfo.document === undefinded){
// Вот тут обрабатываем ошибку в теории
}
Answer the question
In order to leave comments, you need to log in
If you always have a data.noticeInfo object, but sometimes the document property is missing, then you can check for the presence like this:
if('document' in data.noticeInfo)
{
}
if(data.noticeInfo.hasOwnProperty('document'))
{
}
if(typeof data.noticeInfo.document != "undefined" && data.noticeInfo.document !== null)
{
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question