How to display alert box when no json value is given

戏子无情 提交于 2019-12-04 21:21:22

You can do this several different ways:

If bindings is a constant of your object, but may sometimes be empty:

if (data.results.bindings.length) {
    //exists
} else {
    alert('goes here');
}

If bindings is not always set in the response from the server:

if (data.results.hasOwnProperty('bindings')) {
   //exists
} else {
    alert('goes here');
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!