From: Hans-Georg Michna on 13 Feb 2010 13:03 I naively assumed that a call to an XMLHttpRequest with async = true would lead to the program continuing to run after the ..send() action, i.e. the next line of code executed would be the one after .send() and the program would continue to run to the end before any data reception callback would be executed. The readyState event of XMLHttpRequest triggers the processing of the received data under the condition that the data has actually been completely received. But since the data is not received instantly, I think the JavaScript processor could and should do other things, i.e. continue to run past the Ajax call. That, I thought, is the whole purpose of the async parameter in the XMLHttpRequest's open method. However, my test in Internet Explorer 8 indicates that it is not so. Apparently the XMLHttpRequest waits and effectively halts execution until the data is received. The callback function is called a few times, whenever the readyState changes, which is OK. If readyState indicates successful data reception, a further routine, here processAjaxResult, is called, that processes the data. But before that happens and while XMLHttpRequest is waiting for data, I think other parts of the program should continue to run. What am I seeing here? Where is the asynchronicity? Or does the browser always wait for some (I hope smallish) time before it goes async and resumes executing statements after .send()? Or am I seeing things? The basic code sample can be seen and tested at http://winhlp.com/node/684 . When, in the function submitButtonClicked, I move statements down after the ajax(...) call, they are not executed before the incoming data is processed, which seems wrong to me. Any ideas on this one? Hans-Georg
From: Jorge on 14 Feb 2010 06:22 On Feb 13, 7:03 pm, Hans-Georg Michna <hans- georgNoEmailPle...(a)michna.com> wrote: > (...) I wonder why so many people insist in making a simple XHR as complex as... 116 LOCs. -- Jorge.
|
Pages: 1 Prev: The (function (){ })(); Constructor Next: Work at Home- Earn $4,000 With Email Reading Jobs |