changed scope of xhr variable