When I write this Dart code :
for(int i=0;i<nbAleas;i++){
HttpRequest request=new HttpRequest();
// end of request event
request.onReadyStateChange.listen((_) {
if (request.readyState == HttpRequest.DONE &&
(request.status == 200 || request.status == 0)) {
handleResponse(request.responseText);
}
});
// error event
request.onError.listen((Object error)=>handleError(error));
// method and url
request.open("GET", urlServiceRest);
// send the request
request.send();
}
the request is sent only once. I verified it on the server. If I modify the opening like this :
request.open("GET", urlServiceRest, async:false);
it works. Why should the requests be synchronous ?
Also, the above requests are made to the same URL with the same parameters, for example "localhost:8080/random/10/20". If I send to async requests to this URL, only one is sent as said above. If for the second request, I change some parameters "localhost:8080/random/11/21", the two async requests are sent.
Can anyone explain this strange behavior ? Thanks in advance.