Ready function fires before Unload? RRS feed

  • Question

  • Hi.

    I have problem with "Ready" and "Unload" page behavior. Whenever my app navigate from page to another page, the ready function of new page occurs before the unload of previous page. The problem is, I have some async function that need to fire after the page is ready and canceled if navigate from the page before it's ready.

    This is some of my code:

    var promise;
    WinJS.UI.Pages.define("/pages/category/category.html", {
            ready: function (element, options) {
                promise = API.getData(options.catId).then(function (response) {
                    // some work after got the data.
                    promise = null;
            unload: function () {
                // cancel the request
                if (promise && promise.cancel) {

    So, when I navigate from the page to another page (same file with different catId) the "promise = API.getData" in "ready" occurs before "promise.cancel()" in "unload", this behavior "cancel" every request just after I called it.

    How can I fix this? Thanks in advanced and sorry for my bad English.

    Monday, March 17, 2014 7:17 AM


All replies