1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| $.ajax({
type: "GET",
url: "https://site/folder/GetFluxXmlServlet",
dataType: "text",
beforeSend: function () {
Results.innerHTML = 'Loading...<br>';
},
success: function (MAJ) {
var content = MAJ;
document.addEventListener("deviceready", checkIfFileExists, false);
function checkIfFileExists() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
fileSystem.root.getFile("global.xml", { create: false }, fileExists, fileDoesNotExist);
}, getFSFail);
}
function fileExists(fileEntry) {
fileEntry.createWriter(truncateFile, fileDoesNotExist);
}
function truncateFile(writer) {
writer.onwriteend = function (evt) {
console.log("Writer" + evt.code);
writer.seek(0);
writer.onwriteend = function (evt) {
console.log("Changed" + evt.code);
};
writer.write(content);
};
writer.truncate(0);
}
function fileDoesNotExist() {
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onSuccess, onError);
}
function onSuccess(fileSystem) {
var directoryEntry = fileSystem.root;
directoryEntry.getFile("global.xml", {create: true, exclusive: false}, function (fileEntry) {
fileEntry.createWriter(function (writer) {
writer.write(content);
}, function (e) {
console.log("Error :" + e.code);
});
}, function (e) {
console.log("Error :" + e.code);
});
}
function onError(evt) {
console.log("Error :" + evt.code);
}
}
function getFSFail(evt) {
console.log(evt.target.error.code);
}
},
complete: function () {
Results.innerHTML = 'Success';
window.location.reload(true);
}
}) |
Partager