Last modified date of local file. JavaScript

User2 picture User2 · May 22, 2014 · Viewed 11.3k times · Source

In javaScript, currently reading xml files stored in %appdata% using jQuerys $.ajax function. As the file is in %appdata% my javaScript has access to read and write the file.

Example:

/**
* Read a foo.
*/
function readFoo() {
    var xmlFile = "../foo/bar.xml";

        $.ajaxSetup({cache: false});
        $.ajax({
            type: "GET",
            async: true,
            timeout: 5000,
            url : xmlFile,
            dataType : "xml",
            success: parseFoo,
            error: reportFooFail
        });
}

Is it possible using jQuery or plain javaScript to get the files 'last modified' date?

Answer

mohamedrias picture mohamedrias · May 22, 2014

request.getResponseHeader("Last-Modified"); will return you the last-modified date

Use it in the success callback:

success: function(data, textStatus, request){
    var lastModified = request.getResponseHeader("Last-Modified");
 }