locked
windows 8, could not update application data due to xml cache in Javascript Application

    Question

  • I am working on a windows 8 application in javascript. The application fetches a xml periodically from the server, parse the data and update the data in application. When the application is updated, the application is not displaying the latest data instead the previously fetched result is displayed. This may be due to caching of xml data but am not sure about the issue.

    I am using Javascript Grid application.

    The code for xml download is as follows:

     WinJS.xhr({ url: xmlurlFetch }).done(
            function onComplete(result) {
                var xmlDoc = result.responseText; // Response Text from XML
            },
            function onError(err) {
                document.getElementById("dispaly_text").innerHTML = "Error" + err.responseText;
            });

    Wednesday, August 21, 2013 12:57 PM

Answers

  • Hi Shyam,

    Thank you for the quick reply.

    True, the problem is not about the code, I checked it again and you are using a correct code.

    I know someone meet the same problem and they use a dirty solution to solve it: add a ramdam parameter to the url, the parameter will be ignored by the server and you could get the updated result.

    And another official solution is to use headers, the sample code can be:

    WinJS.xhr({ 
        url: "http://www.microsoft.com",
        headers: {
            "If-Modified-Since": "Mon, 27 Mar 1972 00:00:00 GMT"
        } })
        .done(function complete(result) {
            // Report download.
            xhrDiv.innerText = "Downloaded the page";
            xhrDiv.style.backgroundColor = "#00FF00";
    });

    Hope both of them can help you and best regards,

    --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.

    • Marked as answer by Shyam Sundar N Thursday, August 22, 2013 1:48 PM
    Thursday, August 22, 2013 7:00 AM
    Moderator

All replies

  • Hi Shyam,

    I guess that the problem may occurs on you code, I looked into the document for WinJS.xhr and there is sample code, maybe you can try to modify your function name from "onComplete" to "completed":

    WinJS.xhr(options).done(
            function completed(request) {
                // handle completed download.
            }, 
            function error(request) {
                // handle error conditions.
            }, 
            function progress(request) {
                // report on progress of download.
            });

    Best Regards,

    --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.

    Thursday, August 22, 2013 2:06 AM
    Moderator
  • Hi James,

    Thanks for your Reply.

    The suggested solution is not working.

    The problem is not with fetching of data. The query is the latest data is not fetched from the server on update.Instead previously fetched data is displayed.

    The file name fetched from the server is "default.xml".

    How to make sure that the application fetched the xml from the server thereby no cache is stored and referenced.

    Any help is appreciated.

    Regards,

    Shyam Sundar N.



    Thursday, August 22, 2013 3:42 AM
  • Hi Shyam,

    Thank you for the quick reply.

    True, the problem is not about the code, I checked it again and you are using a correct code.

    I know someone meet the same problem and they use a dirty solution to solve it: add a ramdam parameter to the url, the parameter will be ignored by the server and you could get the updated result.

    And another official solution is to use headers, the sample code can be:

    WinJS.xhr({ 
        url: "http://www.microsoft.com",
        headers: {
            "If-Modified-Since": "Mon, 27 Mar 1972 00:00:00 GMT"
        } })
        .done(function complete(result) {
            // Report download.
            xhrDiv.innerText = "Downloaded the page";
            xhrDiv.style.backgroundColor = "#00FF00";
    });

    Hope both of them can help you and best regards,

    --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.

    • Marked as answer by Shyam Sundar N Thursday, August 22, 2013 1:48 PM
    Thursday, August 22, 2013 7:00 AM
    Moderator
  • Hi James,

    Thanks for your continuous help and support.

    I thought of trying the solution you provided.But unfortunately on executing my code it returns the error.

    Unhandled exception at line 1753, column 25 in ms-appx://microsoft.winjs.1.0/js/base.js

    0x800a139e - JavaScript runtime error: SyntaxError

    The same code worked fine the previous day.I tried creating a sample application and it worked fine.I am confused of this behavior.Please help me if you have any solution for this.

    IDE : Visual Studio 2012 Express Edition

    Regards,

    Shyam Sundar N.

    Thursday, August 22, 2013 8:53 AM
  • Hi Shyam,

    It's a really strange behivour. And I looked into the base.js line 1753 and the exception is thrown by onComplete, I suppose your code should looks like below:

     WinJS.xhr({
            url: xmlurlFetch,
            headers: {
                "If-Modified-Since": lastUpdateTime
            }
        })
        .done(
            function complete(result) {
                var xmlDoc = result.responseText; // Response Text from XML
            },
            function error(err) {
                document.getElementById("dispaly_text").innerHTML = "Error" + err.responseText;
            }
         );

    Try to set some break in the base.js line 1746 to see what happens, by the way is JQuery included in your project? I'm not quite sure about this, but I will work on your problem.

    Best Regards,

    --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.

    Thursday, August 22, 2013 9:46 AM
    Moderator
  • Hi James,

    I have included js file in the corresponding pages.

    Can we set breakpoints in base.js file? It is dynamically generated files.

    Regards,

    Shyam Sundar N.

    Thursday, August 22, 2013 10:11 AM
  • Hi James,

    1. The reason for the syntax exception is because of server. The xml returned from the server is the rason for the exception

    2. The update now happening with the code shared by you.

    Thanks for the time and support.

    Regards,

    Shyam Sundar N.

    Thursday, August 22, 2013 1:50 PM
  • Hi Shyam,

    Nice to hear, by the way, you can set breakpoint in base.js, in your project reference, select Windows Library for Javascript 1.0 and then js folder, a base.js exist, and you could set breakpoint in the document.

    But anyway congratulation.

    --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.

    Friday, August 23, 2013 12:38 AM
    Moderator