locked
how to display toast with data received from winJS.xhr ?

    Question

  • Hi,

    I am trying to implement a backgroundTask.js which runs for every 15 min. In that backgroundTask.js I am polling a server using WinJsxhr() ,now I want to bind the data  I received to the toast in order to display the toast notification. But I was facing a problem here...first toast is getting displayed with empty data thereafter WinJs.xhr is getting called...but I need WinJs.xhr() to be called first after completion of that task then my toast need to updated with the response of xhr....

    please help me...This was the code I tried

    (function() {

    "use strict";

        importScripts(

    "//Microsoft.WinJS.1.0.RC/js/base.js");

    vartitle = "";

        WinJS.xhr({ type:

    "Get", url: http://www.xyz.com }).done(function(res) {

    varnotificationData = JSON.parse(res.responseText);

            title = notificationData.title;

        }

        );

       

    varbackgroundTaskInstance = Windows.UI.WebUI.WebUIBackgroundTaskInstance.current;

    varnotification = Windows.UI.Notifications;

     

    vartoastContent = NotificationsExtensions.ToastContent;

    varnotificationManager = notification.ToastNotificationManager;

    varcontent = toastContent.ToastContentFactory.createToastText01();

        content.textBodyWrap.text = title;

    vartoast = content.createNotification();

        notificationManager.createToastNotifier().show(toast);

    })()

    • Edited by sandbha Thursday, July 19, 2012 6:55 PM
    Thursday, July 19, 2012 6:48 PM

Answers

  • Hi Sandeep,

    You need to call your code after the request is .done().

    Put your code inside of the function you defined there:

    .done( function(res){

    Do something in here with the res....

    }


    Jeff Sanders (MSFT)

    Thursday, July 19, 2012 8:14 PM
    Moderator
  • Hi Jeff,

    Thanks for your reply...now my application is working fine...

    • Marked as answer by sandbha Tuesday, July 24, 2012 6:05 PM
    Friday, July 20, 2012 5:50 AM

All replies

  • Hi Sandeep,

    You need to call your code after the request is .done().

    Put your code inside of the function you defined there:

    .done( function(res){

    Do something in here with the res....

    }


    Jeff Sanders (MSFT)

    Thursday, July 19, 2012 8:14 PM
    Moderator
  • Hi Jeff,

    Thanks for your reply...now my application is working fine...

    • Marked as answer by sandbha Tuesday, July 24, 2012 6:05 PM
    Friday, July 20, 2012 5:50 AM