【问题标题】:The connection to ws://localhost:9292/faye was interrupted while the page was loading加载页面时与 ws://localhost:9292/faye 的连接中断
【发布时间】:2012-06-13 07:42:33
【问题描述】:

在 Firefox 的 Firebug 客户端我看到错误

The connection to ws://localhost:9292/faye was interrupted while the page was loading

这是我的 application.js 文件:

$(function() {
    var faye = new Faye.Client('http://localhost:9292/faye');
    alert("connected.");
    faye.subscribe("/game/poker", function(data) {
        eval(data);
    });
});

这是我的 erb.js 文件:

<%= broadcast "/game/poker" do %>
<% @allowed && @user_hand && @game.table.size == 5 && @game.hasler == @game.user.name ? cc = @game.combo_cards(@user_hand) : cc = [1, 2, 3, 4, 5] %>
$("#table").empty().append("<div class='player-cards'>" + "<%= escape_javascript render :partial => "table_cards", :locals => {:cards => @game.table, :combo_cards => cc} %>" + "</div");
$("#deck-size").empty().append("<div class='deck-size'>" + <%= escape_javascript "#{@game.deck.size}" %> +"</div>");
$("#<%= @game.user.name %>_action").empty().append("<%= escape_javascript "#{@game.user.actions.last}" %>");
$("#<%= @game.bot.name %>_action").empty().append("<%= escape_javascript "#{@game.bot.actions.last}" %>");

<% unless @allowed && (@game.bot.moved && @game.user.moved) || @pfold == true %>
    $("#deal").hide();
<% end %>
<% if @game.to_call != 0 %>
    $("#check").hide();
    $("#call").show();
<% else %>
    $("#call").hide();
    $("#check").show();
<% end %>
<% unless !@pfold && !@allowed %>
    $("#fold").hide();
    $("#bet").hide();
    $("#small2").hide();
    $("#small4").hide();
    $("#small8").hide();
    $("#all_in").hide();
<% end %>
<% end %>

问题是广播块内的任何东西都不起作用。浏览器响应只是空的。 广播方式和 railscast 一样:

def broadcast(channel, &block)
    @action = {:channel => channel, :data => capture(&block)}
    @uri = URI.parse("http://localhost:9292/faye")
    Net::HTTP.post_form(@uri, :action => @action.to_json)
    puts "DEBUG::broadcasting channel"
end

我做错了什么?请尽你所能提供帮助。

【问题讨论】:

  • 所以你在广播后收到来自faye的回复到客户端?我会首先检查以确保广播输出的内容用简单的alert() 替换广播中的所有内容,并将广播中的:data 替换为硬编码的内容,以便您可以隔离问题。

标签: ruby-on-rails node.js firefox comet faye


【解决方案1】:

根据您的代码,我假设您不使用 websocket。在你的 application.js 上试试这个,这可能会奏效。告诉我

$(function() {
    var faye = new Faye.Client('http://localhost:9292/faye');
    alert("connected.");
    faye.subscribe("/game/poker", function(data) {
       eval(data);
    });

    faye.disable('websocket');

});

【讨论】:

    猜你喜欢
    • 2012-06-13
    • 1970-01-01
    • 2013-03-05
    • 2014-08-10
    • 2018-01-06
    • 2021-12-27
    • 1970-01-01
    • 1970-01-01
    • 2017-01-01
    相关资源
    最近更新 更多