attempting recursive function to make ajax behave