使用jQuery创建信使应用程序(失败)
Creating a messenger app using jQuery (failed)
我在这里失败了。我是web开发的新手,对HTML/CSS/JS(jQuery)有很好的经验。我试着只使用我所知道的来构建一个聊天应用程序。我把它上传到了一个网络服务器上,发现当其他人在另一台电脑上打字时,其他人也在网站上打字的消息不会出现。我认为让jQuery将元素添加到无序列表中,它会显示给连接到网站的每个人。你认为通过编辑我的一些代码我可以达到我的目标吗?还是我完全偏离了路线,试图做一些不可能的事情(只使用JS/jQuery)。如果是第二个,你能带我朝正确的方向走吗。HTML:
<html>
<head>
<script src="http://www.codehelper.io/api/ips/?js"></script>
<script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
<script src="js/jQuery.js"></script>
<title>Instant Messenger</title>
</head>
<link rel="stylesheet" href="css/style.css"/>
<body>
<div class="Talk">
<ul>
</ul>
</div>
<form>
<div class="Messages">
Message: <input type="text" id="Message" size="100px">
<input type="submit" id="submit">
</div>
</form>
</body>
</html>
CSS:
@import url("http://fonts.googleapis.com/css?family=Source+Sans+Pro:300,900");
.Messages{
position: fixed;
bottom: 10;
}
JS:
$(document).ready(function(){
$("#submit").click(function(e){
//alert(codehelper_ip.IP);
//alert(codehelper_ip.CityName);
e.preventDefault();
var Input = $("#Message").val();
//alert(Input);
$(".Talk ul").append('<li>'+'['+ codehelper_ip.CityName +'~'+codehelper_ip.IP+']'+Input+'</li>');
$("#Message").val("");
});
setInterval(main,500);
});
function main(){
var count = $(".Talk li").length;
if(count >= 20 ){
//alert("20th");
$(".Talk li").remove();
}
}
这与您正在使用的技术无关。您需要Meteor服务器、node.js socket.io服务器或其他将消息从您传输给其他用户的服务器(反之亦然)。目前,你只是将用户键入的消息添加到他浏览器中的页面副本中。聊天应用程序实际上相当困难,您肯定需要更深入地了解Web的工作方式;在大多数网络托管提供商上,你根本无法做到这一点,因为他们只支持Apache(尽管它很棒,但无法为聊天应用程序做需要做的事情)。
相关文章:
- 使用Q节点模块时,Bluemix node.js应用程序部署失败
- fs.readFileSync()在express js应用程序中失败
- 测试Ember.JS应用程序失败,返回ReferenceError:未定义Ember
- Windows 应用商店应用程序 xhr 到 localhost 失败
- 预编译资产失败.推送被拒绝,无法编译 Ruby 应用程序
- 在Windows10通用Javascript应用程序中写入文件有时会失败
- 为什么我在Intellij IDEA 11中调试nodejs应用程序失败
- Outlook和OWA-使用Office应用程序生成令牌并发出EWS请求失败
- Angular Meteor应用程序在localhost中工作,但在部署到服务器时失败
- webpack reactjs应用程序加载失败:Uncaught ReferenceError:未定义snapapp
- 使用jQuery创建信使应用程序(失败)
- 对节点应用程序进行群集时Socket.io websocket授权失败
- 在 React.js 应用程序中,API 调用在存储中失败,我如何将其传输回视图
- 只有在ie8 /9的iframe内,GWT应用程序才会失败
- 使用电子打包器在Cent OS 64位上构建电子应用程序失败
- Meteor Up部署失败,但应用程序在开发中运行良好
- ExtJS应用程序构建失败:ReferenceError: d3未定义
- 带有USB模块的Node webkit应用程序失败
- update'执行失败on 'ApplicationCache':没有应用程序缓存要更新
- KeystoneJs应用程序在服务器启动"节点KeystoneJs "失败