modified script to wait for xhr response