put xhr code in init function