I have written small application which take advantage of new FILE API and FormData to upload the file.
I would like to be able to see how much time file uploading has taken. So I have used XMLHTTPRequest.upload
's events loadstart
and load
for starting the stopwatch and then stopping it when the file is loaded.
However when the file size of uploaded file is small I have noticed that "load" event is fired before the loadstart
event is complete(overlapping). So which is causing following execution sequence as shown in the below logs. You can see that the stopWatch()
function is getting called before the startWatch
is called causing error thrown.
They should be executing exclusively is what I was assuming till I saw this incident.
I am using the FireFox 4Beta 6 version for this testing.
17:55:25 INFO 开发者_StackOverflow社区- xhr loadstart = 0
17:55:26 INFO - xhr load = 0 17:55:26 INFO - percent = 100 17:55:26 INFO - _stopWatch() 17:55:26 INFO - xhr loadstart = end 17:55:26 INFO - _startWatch() = true
So I am confused as as per my thinking at any point in time only once JS statement can be in execution.
Also I am not sure if this is correct behavior? I mean load block's code executing before the loadstart's code block is executed. And if its right behaviour then how should i make sure that load event does not fire before the loadstart has not finished? To prevent the overlapping.
精彩评论