Ruby on rails Ajax回调不适用于Rails 3.0.5和jQuery 1.5.1

Ruby on rails Ajax回调不适用于Rails 3.0.5和jQuery 1.5.1,ruby-on-rails,ruby-on-rails-3,jquery,Ruby On Rails,Ruby On Rails 3,Jquery,我在我的网站上使用了ajax分页,但我很难使用ajax回调 我使用的是jquery-1.5.1、rails 3.0.5,我有最新的rails.js文件 我的podcasts.html.haml如下所示 #paginator = paginate @podcasts, :remote => true #podcasts = render @podcasts 我的index.js.erb文件如下所示: $('#podcasts').html('<%= escape_javas

我在我的网站上使用了ajax分页,但我很难使用ajax回调

我使用的是jquery-1.5.1、rails 3.0.5,我有最新的rails.js文件

我的
podcasts.html.haml
如下所示

#paginator
  = paginate @podcasts, :remote => true

#podcasts
  = render @podcasts
我的index.js.erb文件如下所示:

$('#podcasts').html('<%= escape_javascript render(@podcasts) %>');
$('#paginator').html('<%= escape_javascript(paginate(@podcasts, :remote => true).to_s) %>');
我希望上述代码在ajax工作完成后发出警报。但是什么也没有发生

有人有什么想法吗

附言 上面的paginate方法来自,它创建以下html:

<div id="paginator">
  <nav class="pagination">
    <a href="/podcasts" data-remote="true">Page 1</a>
    <a href="/podcasts?page=2" data-remote="true">Page 2</a>
    <a href="/podcasts?page=3" data-remote="true">Page 3</a>
  </nav>
</div>

我无法完全理解您的代码,但我做了一个简单的测试(jquery 1.5.1、rails 3.0.5),它对我很有用:

ajax\u controller.rb

class AjaxController < ApplicationController
  def get_data
    respond_to do |format|
      format.js { sleep 1; render :json => "ajax value" }
    end
  end
end
<%= link_to "get_data", get_data_path, :remote => true, :id => 'request' %>

<div id="response">
</div>

<%= javascript_tag do %>
    $("#response").html("default value");

    $("#request").bind("ajax:success", function(e, data, status, xhr) {
        $("#response").html(data);
    });
<% end %>
    get "ajax/index"
    get "ajax/get_data", :as => "get_data"

我希望这能有所帮助。

我不能完全按照您的代码进行操作,但我做了一个简单的测试(jquery 1.5.1、rails 3.0.5),它对我很有用:

ajax\u controller.rb

class AjaxController < ApplicationController
  def get_data
    respond_to do |format|
      format.js { sleep 1; render :json => "ajax value" }
    end
  end
end
<%= link_to "get_data", get_data_path, :remote => true, :id => 'request' %>

<div id="response">
</div>

<%= javascript_tag do %>
    $("#response").html("default value");

    $("#request").bind("ajax:success", function(e, data, status, xhr) {
        $("#response").html(data);
    });
<% end %>
    get "ajax/index"
    get "ajax/get_data", :as => "get_data"

我希望这能有所帮助。

hey@plang,谢谢你,我今晚晚些时候会有机会尝试一下,但建议看起来不错,而且很有意义,所以我想我可以用它解决问题。再次感谢,谢谢你,今晚晚些时候我会有机会尝试一下,但是建议看起来很好,很有道理,所以我想我可以用它解决问题。再次感谢,我也有同样的问题,它看起来像
$('paginator').html('true.to_)%>)此行导致回调停止。如果您将其更改为
.html
.append
,它将提供回调..但不幸的是,它使用了重复分页链接。你解决了这个问题吗?我也有同样的问题,它看起来像
$('paginator').html('true.to_)%>)此行导致回调停止。如果您将其更改为
.html
.append
,它将提供回调..但不幸的是,它使用了重复分页链接。你解决这个问题了吗?