编辑#2:嗯,重新启动计算机后错误消失了。我没有改变任何事情。另一个好日子浪费在一个甚至不存在的错误上......
我想你可以删除它吗?
我的代码之前没有任何路由工作正常,但后来这种情况开始发生,我没有像一天那样提交,所以我不想加载我的上一次保存。这是什么意思,我该如何解决?
我真的不知道该问什么,因为当你搜索&#34时,我没有遇到任何类似的事情;无法获得/ null nodejs"在谷歌上。如果你想让我发布,我有500行代码。
_________________________________
<!doctype html>
<html>
<body>
<div id="signDiv">
Username: <input id="signDiv-username" type="text"></input><br>
Password: <input id="signDiv-password" type="password"></input><br>
<button id="signDiv-signIn">Sign in</button>
<button id="signDiv-signUp">Sign up</button>
</div>
<div id="gameDiv" style="display:none;">
<canvas id="ctx" width="500" height="500" style="border:1px solid #000000;"></canvas>
<div id="chat-text" style="width:500px; height:100px; overflow-y:scroll">
<div>Hello</div>
</div>
<form id="chat-form">
<input id="chat-input" type="text" style="width:500px"></input>
</form>
</div>
<script src="http://cdn.socket.io/socket.io-1.4.5.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script type="text/javascript">
var userip;
</script>
<script type="text/javascript" src="https://l2.io/ip.js?var=userip"></script>
<script type="text/javascript">
document.write("Your IP is :", userip);
</script>
<script>
var socket = io();
//sign in/up
var signDiv = document.getElementById('signDiv');
var signDivUsername = document.getElementById('signDiv-username');
var signDivSignIn = document.getElementById('signDiv-signIn');
var signDivSignUp = document.getElementById('signDiv-signUp');
var signDivPassword = document.getElementById('signDiv-password');
signDivSignIn.onclick = function(){
socket.emit('signIn',{username:signDivUsername.value,password:signDivPassword.value});
};
signDivSignUp.onclick = function(){
socket.emit('signUp',{username:signDivUsername.value,password:signDivPassword.value});
};
socket.on('signInResponse', function(data){
if(data.success){
signDiv.style.display = 'none';
gameDiv.style.display = 'inline-block';
} else
alert("Sign in unsuccessul.");
});
socket.on('signUpResponse', function(data){
if(data.success){
alert("Sign up successful.");
} else
alert("Sign up unsuccessul.");
});
var chatText = document.getElementById("chat-text");
var chatInput = document.getElementById("chat-input");
var chatForm = document.getElementById("chat-form");
var ctx = document.getElementById("ctx").getContext("2d");
ctx.font = "30px Arial";
socket.on('newPositions', function (data){
ctx.clearRect(0,0,500,500);
for(var i=0 ; i < data.player.length; i++)
ctx.fillText(data.player[i].number, data.player[i].x, data.player[i].y);
for(var i=0 ; i < data.bullet.length; i++)
ctx.fillRect(data.bullet[i].x-5, data.bullet[i].y-5, 10, 10);
});
// socket.on('hit event', function(linkbulletdata){
// window.location=String(linkbulletdata);
// signDiv.style.display = 'inline-block';
// gameDiv.style.display = 'none';
// });
socket.on('addToChat', function(data){
chatText.innerHTML += '<div>' + data + '</div>';
});
socket.on('evalAnswer', function(data){
console.log(data);
});
chatForm.onsubmit = function(e){
e.preventDefault();
if(chatInput.value[0] === '/') {
socket.emit('evalServer', chatInput.value.slice(1));
}
else {socket.emit('sendMsgToServerLoadGun', chatInput.value);}
chatInput.value = '';
}
$(document).ready(function(){
$("body").keydown(function(e){
switch(e.which) {
case 32: //space ATTACK
socket.emit('keyPress', {inputId:'attack', state:true});
console.log('shoot');
break;
case 37: // left
socket.emit('keyPress', {inputId: 'left', state: true });
console.log("keycode= " + e.keyCode);
break;
case 38: // up
socket.emit('keyPress', {inputId: 'up', state: true });
console.log("keycode= " + e.keyCode);
break;
case 39: // right
socket.emit('keyPress', {inputId: 'right', state: true });
console.log("keycode= " + e.keyCode);
break;
case 40: // down
socket.emit('keyPress', {inputId: 'down', state: true });
console.log("keycode= " + e.keyCode);
break;
default: return; // exit this handler for other keys
}
e.preventDefault(); // prevent the default action (scroll / move caret)
});
});
document.onmousemove = function(event){
var x = -250 + event.clientX -8;
var y = -250 + event.clientY -8;
var angle = Math.atan2(y,x)/Math.PI*180;
socket.emit('keyPress', {inputId:'mouseAngle', state:angle});
}
document.onmousedown = function(event){
socket.emit('keyPress', {inputId:'attack', state:true});
}
document.onmouseup = function(event){
socket.emit('keyPress', {inputId:'attack', state:false});
}
$(document).ready(function(){
$("body").keyup(function(e){
switch(e.which) {
case 32: //space
console.log('space');
socket.emit('keyPress', {inputId:'attack', state:false});
break;
case 37: // left
socket.emit('keyPress', {inputId: 'left', state: false });
console.log("keycode= " + e.keyCode);
break;
case 38: // up
socket.emit('keyPress', {inputId: 'up', state: false });
console.log("keycode= " + e.keyCode);
break;
case 39: // right
socket.emit('keyPress', {inputId: 'right', state: false });
console.log("keycode= " + e.keyCode);
break;
case 40: // down
socket.emit('keyPress', {inputId: 'down', state: false });
console.log("keycode= " + e.keyCode);
break;
default: return; // exit this handler for other keys
}
e.preventDefault(); // prevent the default action (scroll / move caret)
});
});
</script>
</body>
</html>
答案 0 :(得分:1)
问题很可能不在于您的node.js服务器代码,而在于您的客户端代码。如果我启动express.js服务器,然后在浏览器中访问localhost:3000/null
,我可以重现此错误。浏览器返回时不能GET / null&#39;。
因此,如果没有任何进一步的信息,问题很可能与您的客户端代码有关:从您的node.js服务器请求信息的代码。最有可能的原因是:它看起来像你的一个js对象,客户端代码被设置为null
,然后该对象被用作对node.js服务器的请求的路径。您的服务器可能没有/null
的路由,因此您会看到该错误。
希望有所帮助!如果我完全走错了轨道,请随意发布一些客户端代码。