无法在互联网上部署我的程序

时间:2017-10-30 15:11:49

标签: javascript user-interface processing

我使用GUI的Processing Library在JavaScript中创建了一个TicTacToe程序。现在我想把它放在一个网站上。 processing.js允许我们这样做,但尽管经过多次尝试,我似乎无法让它发挥作用。

我正在上传文件here。它包含我的Processing sketch,我的html文件和processing.js文件。还包含我在算法中使用的文本文件。

首先,我尝试使用以下语法直接使用草图:

<script src="processing.js"></script> 
<canvas data-processing-sources="anything.pde"></canvas>

但是当我这样做时,我的浏览器只显示了一个空白页面。接下来,我尝试将所有代码放在html文件本身中,如在processing.js网站上提到的那样。当我这样做游戏加载到页面上时,我可以移动,但计算机不会按照预期进行移动。我已经对程序进行了广泛的测试,它确实在Processing IDE中运行。

更新: 所以我检查了JavaScript控制台,发现我程序中使用的possibilities.txt文件没有加载。以下是控制台所说的内容:

processing.js:11 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
ajax @ processing.js:11
p.loadStrings @ processing.js:13904
fillStore @ VM56:340
caller @ VM56:164
mouseClicked @ VM56:121
(anonymous) @ processing.js:7613
processing.js:16 Failed to load file:///D:/possibilities.txt: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
ajax @ processing.js:16
p.loadStrings @ processing.js:13904
fillStore @ VM56:340
caller @ VM56:164
mouseClicked @ VM56:121
(anonymous) @ processing.js:7613
processing.js:16 Uncaught DOMException: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file:///D:/possibilities.txt'.
    at ajax (http://localhost:8081/processing.js:16:9)
    at Processing.Processing.p.loadStrings (http://localhost:8081/processing.js:13904:25)
    at Processing.Processing.fillStore (eval at attach (http://localhost:8081/processing.js:718:22), <anonymous>:340:16)
    at Processing.Processing.caller (eval at attach (http://localhost:8081/processing.js:718:22), <anonymous>:164:3)
    at Processing.Processing.mouseClicked (eval at attach (http://localhost:8081/processing.js:718:22), <anonymous>:121:6)
    at HTMLCanvasElement.<anonymous> (http://localhost:8081/processing.js:7613:9)
ajax @ processing.js:16
p.loadStrings @ processing.js:13904
fillStore @ VM56:340
caller @ VM56:164
mouseClicked @ VM56:121
(anonymous) @ processing.js:7613

还在localhost服务器上托管该文件并尝试..仍然没有运气。控制台显示此错误:

processing.js:11 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
ajax @ processing.js:11
p.loadStrings @ processing.js:13904
fillStore @ VM25:340
caller @ VM25:164
mouseClicked @ VM25:121
(anonymous) @ processing.js:7613
processing.js:16 Failed to load http://localhost:8081/possibilities.txt: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'file://' is therefore not allowed access.
ajax @ processing.js:16
p.loadStrings @ processing.js:13904
fillStore @ VM25:340
caller @ VM25:164
mouseClicked @ VM25:121
(anonymous) @ processing.js:7613
processing.js:16 Uncaught DOMException: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://localhost:8081/possibilities.txt'.
    at ajax (file:///D:/web/processing.js:16:9)
    at Processing.Processing.p.loadStrings (file:///D:/web/processing.js:13904:25)
    at Processing.Processing.fillStore (eval at attach (file:///D:/web/processing.js:718:22), <anonymous>:340:16)
    at Processing.Processing.caller (eval at attach (file:///D:/web/processing.js:718:22), <anonymous>:164:3)
    at Processing.Processing.mouseClicked (eval at attach (file:///D:/web/processing.js:718:22), <anonymous>:121:6)
    at HTMLCanvasElement.<anonymous> (file:///D:/web/processing.js:7613:9)
ajax @ processing.js:16
p.loadStrings @ processing.js:13904
fillStore @ VM25:340
caller @ VM25:164
mouseClicked @ VM25:121
(anonymous) @ processing.js:7613

1 个答案:

答案 0 :(得分:0)

您需要查看the JavaScript console以查看代码丢失的任何错误。

无耻的自我推销:我编写了一个关于使用Processing.js部署Processing的教程,可用here

你还没有发布MCVE(请在将来尝试这样做)所以我无法确切知道发生了什么,但我的猜测是你在使用仅Java的功能你的代码,导致JavaScript抛出错误。如果是这种情况,那么您将需要摆脱Java代码。