出现 Cannot read property 'xxxxxx' of null 问题思路

在Console中出现 Cannot read property 'xxxxxx' of null  的问题时很难查找到改原因的出处

今天在项目中看到页面出现 Cannot read property 'xxxxxx' of null 的字样如下:

出现 Cannot read property 'xxxxxx' of null 问题思路

对于像我这样的前端菜鸡根本,一开始以为是layer插件出现了问题

尝试一:修改alyer语句依旧报错    无效

尝试二:注释掉该页面所有alyer有关的代码    无效

百般不得其解的情况下将整个方法注释发现不报错了。。。

于是在该方法内进行degugger;

发现在执行到ajax后出现了上述报错,打印回调函数内容发现后台返回的结果是 null

结果显而易见,应该是后台的问题

于是我更变参数后,正确请求到数据后,报错就消失了。


总结:出现Cannot read property 'xxxxxx' of null 的错误时,未必是前端js的问题,可能是后台传过来的值导致前台报错。