我使用这个页面做了一个简单的faye教程应用程序:
http://code.tutsplus.com/tutorials/how-to-use-faye-as-a-real-time-push-server-in-rails--net-22600
并且得到了消息显示的一个常见问题--服务器获取一个参数并呈现它,但是页面上什么也没有发生。我已经修复了faye.ru文件,正如在评论中推荐的那样。我该怎么办?
大部分代码存储在视图中:
<script>
$(function() {
// Subscribe to receive messages!
var client = new Faye.Client('http://localhost:9292/faye');
// Our public subscription
var public_subscription = client.subscribe('/messages/public', function(data) {
$('<p></p>').html(data.username + ": " + data.msg).appendTo('#chat_room');
});
// Our own private channel
var private_subscription = client.subscribe('/messages/private/<%= session[:username] %>', function(data) {
$('<p></p>').addClass('private').html(data.username + ": " + data.msg).appendTo('#chat_room');
});
// Handle form submission to publish messages.
$('#new_message_form').submit(function(){
// Is it a private message?
if (matches = $('#message').val().match(/@(.+) (.+)/)) {
client.publish('/messages/private/' + matches[1], {
username: '<%= session[:username] %>',
msg: matches[2]
});
}
else {
// It's a public message
client.publish('/messages/public', {
username: '<%= session[:username] %>',
msg: $('#message').val()
});
}
// Clear the message box
$('#message').val('');
return false;
});
});
<div class="chat_container">
<div id="chat_room">
<p class="alert"> Welcome to the chat room <%= session[:username] %>! </p>
</div>
<form id="new_message_form">
<input type="text" id="message" name="message">
<input type="submit" value="Send">
</form>
</div>发布于 2015-07-21 09:15:42
https://stackoverflow.com/questions/31501546
复制相似问题