locked
Synchronous WinJS.xhr Request

    Question

  • Would someone please tell us how to do a Synchronous WinJS.xhr Request in a windows 8 app.  The XMLHttpRequest.open method for varAsync is missing in the documentation.

    • Edited by Mark Ebling Monday, March 25, 2013 7:42 AM Too Harsh - Was in a bad mood
    Sunday, March 24, 2013 7:14 AM

Answers

  • Not that I approve of the tone of your post, but you know that you don't have to use WinJS.xhr, you can just use JS standard way of doing it:

    var req = new XMLHttpRequest();
    // false =  synchronous
    req.open("get", "yourFile.txt", false);
    req.send();

    • Marked as answer by Mark Ebling Monday, March 25, 2013 8:39 AM
    Sunday, March 24, 2013 7:46 AM

All replies

  • Not that I approve of the tone of your post, but you know that you don't have to use WinJS.xhr, you can just use JS standard way of doing it:

    var req = new XMLHttpRequest();
    // false =  synchronous
    req.open("get", "yourFile.txt", false);
    req.send();

    • Marked as answer by Mark Ebling Monday, March 25, 2013 8:39 AM
    Sunday, March 24, 2013 7:46 AM
  • Hi Andy,

    I deleted the majority of my post.  Sorry, was in a really bad mood.

    It turns out I was not understanding the error:

    0x800c001c - JavaScript runtime error: Unable to add dynamic content.

    I incorrectly assumed that a raw XMLHttpRequest was not supported and that's when I started reading about WinJS.xhr.

    I solved the problem by wrapping MSApp.execUnsafeLocalFunction around the innerHTML insert of the returned results.  All of our HTML content is created dynamically and this was the best solution I could find for needing to use innerHTML.

    • Edited by Mark Ebling Saturday, July 13, 2013 1:47 AM Wrong Code
    Monday, March 25, 2013 8:39 AM