locked
WinJS.xhr() just working first time

    Question

  • Hello everyone,

    inside a file called xml.js, I have one function linked to a button.



     exportDocumentImage: function () {

    var xmlDocument = new Windows.Data.Xml.Dom.XmlDocument();

    ...

    xmlDocument.saveToFileAsync(filedata).done(function () { createFile().done( function success(result) { var date = new Date(); WinJS.log(date + " Finish "); }, function error(result) { WINJS.log(" error " + error.responseText); }); });

    }

     function createFile() {
    
            var date = new Date();
            return WinJS.xhr({
                url: "http://example.com",
                type: "GET",
            }).then(
                function succes(result) {
                    // Obtain the date that will be formatted. 
                    var date = new Date();
    
                    WinJS.log(date + "File created. Response Text " + result.responseText + "  Status " + result.status + " " + result.statusText);
                    
                },
                function error(result) {
                    WinJS.log("Error  creatingFile " + result.responseText);
    
                    
                }
            );

    But when I run the application, the web service is called just the first time. After that, stops to work, and I need to restart the application.
    What is my problem?
    I'm able to see al the log files, so the application seems to run ok, but the webservice is not being called
    Thanks in advanced

    David





    • Edited by DavidFEG Tuesday, February 18, 2014 3:28 PM
    Tuesday, February 18, 2014 3:23 PM

Answers

  • This usually indicates a caching problem. Use "If-Modified-Since" header in your xhr code:

        function acquireSyndication(url) {
            return WinJS.xhr({
                url: url,
                headers: { "If-Modified-Since": "Mon, 27 Mar 1972 00:00:00 GMT" }
            });
        }

    Wednesday, February 19, 2014 12:17 AM
  • Vote Mike, additionally a documentation for you: How to ensure that WinJS.xhr resends requests

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, February 19, 2014 1:31 AM
    Moderator

All replies

  • This usually indicates a caching problem. Use "If-Modified-Since" header in your xhr code:

        function acquireSyndication(url) {
            return WinJS.xhr({
                url: url,
                headers: { "If-Modified-Since": "Mon, 27 Mar 1972 00:00:00 GMT" }
            });
        }

    Wednesday, February 19, 2014 12:17 AM
  • Vote Mike, additionally a documentation for you: How to ensure that WinJS.xhr resends requests

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, February 19, 2014 1:31 AM
    Moderator
  • Thanks everyone ,

    WinJS.xhr({
                url: "http://example.com",
                headers: { "If-Modified-Since": "Mon, 27 Mar 1972 00:00:00 GMT" }
            })

    actually works ...



    • Edited by DavidFEG Wednesday, February 19, 2014 9:46 AM
    Wednesday, February 19, 2014 9:44 AM