Elance Exams Answers PDF file

-- PDF FILE --
Download PDF file of elance Zoho Creator Exam Answers

What's wrong with the following code? function check_for_request_done() { if (xhr.readyState == 4) { clearInterval(timer); do_something_with_result(xhr); } } var xhr = new XMLHttpRequest(); xhr.open("GET", "/resource", true); xhr.send(); var timer = setInterval(check_for_request_done, 100);

The resource is being fetched synchronously so there's no need to wait for a response.
The wrong readystate value is being checked for a complete request. The response should only be used when readyState == 5.
The timer interval (100ms) is way too fast, a longer polling interval should be chosen to detect for response.
This code is polling a timer rather using the onreadystatechange event to check the state of the async request.
  • Follows us our servcies
  • Facebook icon
  • Linkedin icon
  • twitter icon
  • rss icon
  • social icon