From c4d11b1ee5653616b99a55d0c4eda7f2cec21a5c Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Sat, 30 May 2020 19:03:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8ajax=E8=8E=B7=E5=BE=97index.h?= =?UTF-8?q?tml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _server/editor.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/_server/editor.js b/_server/editor.js index e31d6a3c..aefd65fb 100644 --- a/_server/editor.js +++ b/_server/editor.js @@ -152,8 +152,14 @@ editor.prototype.init = function (callback) { editor.airwallImg = new Image(); editor.airwallImg.src = './project/materials/airwall.png'; - fs.readFile("index.html", 'utf-8', function(err, data) { - var str = data.split(''); + var xhr = new XMLHttpRequest(); + xhr.open('GET', 'index.html', true); + xhr.onload = function () { + if (xhr.status != 200) { + alert("HTTP " + xhr.status); + return; + } + var str = xhr.response.split(''); if (str.length != 3) window.onerror("index.html格式不正确"); editor.dom.gameInject.innerHTML = str[1]; @@ -252,8 +258,11 @@ editor.prototype.init = function (callback) { mainScript.id = "mainScript"; mainScript.src = "main.js"; editor.dom.gameInject.appendChild(mainScript); - }) - + }; + xhr.onabort = xhr.ontimeout = xhr.onerror = function () { + alert("无法访问index.html"); + } + xhr.send(); } editor.prototype.mapInit = function () {