我正在通过使用https://code.kx.com/v2/wp/websockets/的引用来使用websocket开发Web应用程序。
该应用程序位于以下路径:
Directory structure:
/Users/repos/chatu/
-->html
--> main.html
--> main.js
-->q
--> main.q
q)\pwd
"/Users/repos/chatu" //- and main.html(index) is at path /Users/repos/chatu/html/main.html
当pwd为“ / Users / repos / chatu”时,网页将在浏览器上使用url- http:// localhost:5001 / main.html正确打开
但是当pwd更改为任何其他目录时,例如
q)\pwd
"/Users/repos"
然后,击中与上述相同的网址会引发以下错误:
html/main.html: not found
从错误中我可以理解的是,Web服务器期望在当前工作目录中使用html / main.html,但无法找到它。
如何/在哪里可以为index.html设置绝对路径,以使Web浏览器可以从任何当前工作目录中找到main.html页面?(无法找到/理解解决相同问题的任何答案)。
Code snippet -
main.js
function connect(){
if ("WebSocket" in window) {
ws = new WebSocket("ws://localhost:5001/");
output.value="connecting...";
/* ws.onopen=function(e){output.innerHTML="connected"}; */
ws.onclose=function(e){output.innerHTML="disconnected"};
ws.onerror=function(e){output.value=e.data};
/*
when a message is received,
prepend the message to the display area
along with the input command
*/
} else alert("WebSockets not supported on your browser.");
}
main.html
<!doctype html>
<html>
<head>
<title>Chatu</title>
<style>
/* define some CSS styling on page elements */
div#wrap{
width:100%;
overflow:auto;
}
textarea#txtInput {width: 97.5%; height: 60px; float:left; padding: 10px; margin-top: 10px;}
div#txtOutput{
width: 97.5%; height: 300px; font-family: "Courier New"; padding: 10px;
border: 1px solid gray; margin-top: 2px; overflow:auto;
}
</style>
</head>
<body>
<div id="wrap">
<fieldset id='heads' style="border:1; border-radius:10px">
<legend align="center" style="color:blue">Chatu</legend>
<div id="txtOutput"></div>
<textarea id="txtInput" autofocus></textarea>
</fieldset>
</div>
</body>
<script type="text/javascript" src="main.js"></script>
</html>
main.q
.z.ws:{neg[.z.w].j.j @[.da.mf;x;{`$ "'",x}];};
.h.HOME是您感兴趣的变量
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句