Why don't you do this check inside the success callback of the ajax request on line 118?