You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Jesse MacFadyen (JIRA)" <ji...@apache.org> on 2014/05/27 23:19:05 UTC

[jira] [Commented] (CB-6763) Simultaneous local XHRs on WP8 returns incorrect result

    [ https://issues.apache.org/jira/browse/CB-6763?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14010287#comment-14010287 ] 

Jesse MacFadyen commented on CB-6763:
-------------------------------------

The example above is a classic closure issue, and not related to the XHRHelper class, or the JS code it injects.

>From : http://stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example
{code}
var funcs = [];
for (var i = 0; i < 3; i++) {          // let's create 3 functions
    funcs[i] = function() {            // and store them in funcs
        console.log("My value: " + i); // each should log its value.
    };
}
for (var j = 0; j < 3; j++) {
    funcs[j]();                        // and now let's run each one to see
}
{code}

My value: 3
My value: 3
My value: 3

> Simultaneous local XHRs on WP8 returns incorrect result
> -------------------------------------------------------
>
>                 Key: CB-6763
>                 URL: https://issues.apache.org/jira/browse/CB-6763
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: WP8
>    Affects Versions: 3.4.0
>            Reporter: Vladimir Kotikov
>            Assignee: Jesse MacFadyen
>              Labels: wp8, xhr, xhrhelper
>
> When try to get content of multiple local files via XHR, all requests return responses with same content. E.g. following code (using jQuery)
> {noformat}
> function loadTemplates (views) {
>     var deferreds = [];
>     $.each(views, function (index, view) {
>         var vURL = 'tpl/' + view + '.html';
>         deferreds.push($.get(vURL, function (data) {
>             console.log(data)
>         }, 'html'));
>     })
> }
> loadTemplates(["HomeView", "ContactView", "ShellView", "EmployeeView", "EmployeeSummaryView", "EmployeeListItemView"]);
> {noformat}
> will print contents of {{tpl/EmployeeListItemView.html}} 6 times.
> The problem is when new local XHR is sent, it overrides {{__onXHRLocalCallback}} callback, already created by previous request.



--
This message was sent by Atlassian JIRA
(v6.2#6252)