use xhr.onreadystatechange instead of timer