XHRHelper is failing in processing mutiple simultaneous asynchronous AJAX requests. I am using the latest code from https://github.com/apache/cordova-wp8/blob/master/wp8/template/cordovalib/XHRHelper.cs
The problem is related with _onXHRLocalCallback which is save into the window object as a unique function. When, for example, two Ajax requests are evaluated at same time, the last funk function overrides the first _onXHRLocalCallback without receive the data from the C# code to that particular request.
To demostrate this I put console.log("XHR: " + resolvedUrl); inside __onXHRLocalCallback and System.Diagnostics.Debug.WriteLine("HandleCommand: " + url); in HandleCommand method (my code uses Require JS to load this resources). The output is this:
As you can see, one request is missing: "HomeView.html".
- If I set false the this.isAsync variable it works (this way it is executed without using setTimeout).
- If I put a console.log before launch funk it works.
- It works on the simulator, but it fails on a real device.
In conclusion, I assumed that it's a timing problem. To resolve it I decided to save a onXHRLocalCallback function per each request:
So I had to change in HandleCommand method the way of invoking this callback. I decided to create a helper function to be called in each case:
To be called as InvokeCallback(url, 200, text); or InvokeCallback(url, 404, null);