diff --git a/src/js/gcode-viewer.js b/src/js/gcode-viewer.js index 658382c..633a8d5 100644 --- a/src/js/gcode-viewer.js +++ b/src/js/gcode-viewer.js @@ -80,33 +80,29 @@ module.exports = { methods: { - load: function (file) { + load: async function(file) { if (file == this.file) return; this.clear(); this.file = file; if (!file) return; - var xhr = new XMLHttpRequest(); - xhr.open('GET', '/api/file/' + file + '?' + Math.random(), true); - xhr.responseType = 'text'; + const response = await fetch(`/api/file/${file}?${Math.random()}`); + const text = await response.text(); - xhr.onload = function (e) { - if (this.file != file) return; - var lines = escapeHTML(xhr.response.trimRight()).split(/\r?\n/); - - for (var i = 0; i < lines.length; i++) { - lines[i] = '