Organizational Research By

Surprising Reserch Topic

passing some argument to the callback function of WinJs xhr


In Windows 8, I am using WinJs.xhr in a loop to download some content, and as it arrives afterward to the "done callback", I would like to pass an argument to retrieve the element who call xhr.

    for (var k = 0 ; k < 9; k++) {
                        var title = dataArray[k].name;
                        if (title != null)
                            url = monUrl+ title;

                        WinJS.xhr({ url: url, responseType: "responseXML" })
   .done(function complete(result) {

    //I would like to retrieve the right title here for example
       var dataArray = new Array();
       var xml = result.responseXML;
 }
}

Thank you for your help

asked Sep 13, 2013 in Microsoft Window 8 by rajesh
edited Sep 12, 2013
0 votes
76 views



Related Hot Questions

1 Answer

0 votes
You'll need to capture it in a closure, which with vanilla for loops/iteration is a pain: for (var k = 0 ; k < 9; k++) { (function(item) { var url; var title = item.name; if (title != null) url = monUrl+ title; WinJS.xhr({ url: url, responseType: "responseXML" }).done(function complete(result) { // I would like to retrieve the right title here for example var dataArray = new Array(); var xml = result.responseXML; /* use your title property here */ }); })(dataArray[k]); }
answered Sep 13, 2013 by rajesh
edited Sep 12, 2013

...