2012-06-13 96 views
1

在在Firefox中的Firebug客戶端9292 /王菲被打斷我看到錯誤到WS連接://本地主機:當網頁被加載

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 [email protected] && [email protected] %> 
    $("#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 

我做錯了嗎?請幫助你做任何事情。

+0

所以,你在廣播後得到了來自faye的響應到客戶端?我會首先檢查以確保廣播正在輸出一些東西,用簡單的'alert()'替換廣播中的所有內容,並用硬編碼代替廣播中的':data',這樣就可以隔離問題。 –

回答

0

基於你的代碼,我假設你不使用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'); 

});