我制作一个聊天应用程序。当我运行这个应用程序时,在输入框中输入一些内容并发送,没有任何反应。
我在控制台中遇到错误
localhost/:1 Refused to apply style from 'http://localhost:3001/style.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
app.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
angular2.js:679 Uncaught ReferenceError: System is not defined
at angular2.js:679
app.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
localhost/:1 Refused to execute script from 'http://localhost:3001/js/app.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
localhost/:1 Refused to apply style from 'http://localhost:3001/style.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
<!doctype html>
<html ng-app="myApp">
<head>
<title>Socket.IO chat</title>
<link rel="stylesheet" href="style.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/2.0.0-alpha.20/angular2.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.1.1/socket.io.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js">
</script>
<script src="js/app.js"></script>
</head>
<body ng-controller="mainController">
<ul id="messages"></ul>
<div>
<input id="m" ng-model="message" autocomplete="off" />
<button ng-click="send()">Send</button>
</div>
</body>
</html>
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req, res){
res.sendfile('index.html');
});
io.on('connection', function(socket){
console.log('user connected');
socket.on('chat message', function(msg){
io.emit('chat message', msg);
});
socket.on('disconnect', function(){
console.log('user disconnected');
});
});
http.listen(3001, function(){
console.log('listening on *:3001');
});
var app=angular.module('myApp',[]);
app.controller('mainController',['$scope',function($scope){
var socket = io.connect();
$scope.send = function(){
socket.emit('chat message', $scope.message);
$scope.message="";
}
socket.on('chat message', function(msg){
var li=document.createElement("li");
li.appendChild(document.createTextNode(msg));
document.getElementById("messages").appendChild(li);
});
}]);
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font: 13px Helvetica, Arial; }
div { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
div input { border: 0; padding: 10px; width: 90%; margin-right: .5%; }
div button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; }
#messages { list-style-type: none; margin: 0; padding: 0; }
#messages li { padding: 5px 10px; }
#messages li:nth-child(odd) { background: #eee; }
发布于 2018-06-14 12:44:35
我猜你的问题来源:
发布于 2018-06-14 13:48:09
你需要学习调试和解决问题。开发人员不存在“没有任何反应”。尝试通过减少小问题中的问题来解决问题。例如问自己这些问题:
1.期望的输出是什么(显示消息)2.我的输入是什么(点击按钮)3.我的控制台中是否有错误?
答案告诉你在代码中查找的地方。例如,从想要从按钮点击获取回调的位置开始。在那里添加一些记录。你看到什么了吗?
https://stackoverflow.com/questions/-100004910
复制相似问题