Added a check if invalid or error occured during ajax query

Signed-off-by: Arpit Goyal <agmps17@gmail.com>