0

I have a getjson which logs successfully if I give correct data.value, if I give invalid data.value it shows an empty array[] on browser, how can I identify json returns an empty array [] using my getjson code, I have tried below code but not work, if I give invalid data.value. Need your help.

$.getJSON("http://xxx.xx.xx/mobapp/api/get-pli-details?id=" + data.value, function (result) {
    console.log('here ' + result[0].email);
    if (result[0] === null) {
        popup("<h3>M-Elec</h3>Invalid PLI ID");
    } else {
        email = result[0].email;
        userType = result[0].utype;
        name = result[0].name;
    }
});
Mumthezir VP
  • 5,359
  • 5
  • 24
  • 54

2 Answers2

0

Try this

$.getJSON(url,function(result){
    if ( result.length == 0 ) {
        console.log("NO DATA!")
    }
});
Sridhar R
  • 19,414
  • 6
  • 36
  • 35
  • @mvp: If you just say "not works", then we cannot help you further. [Learn how to **debug** JavaScript](http://www.creativebloq.com/javascript/javascript-debugging-beginners-3122820) to help yourself. – Felix Kling Dec 19 '13 at 05:06
  • @mvp so your url did not return anything right.so use success and failure promise callbacks – Sridhar R Dec 19 '13 at 05:17