English 中文(简体)
铁路Ajax:作为案文而不是执行
原标题:Rails Ajax: .js.erb rendered as text, not executed

I m, using jquery-rails gem with javascript_include_tag :defaults. 因此,该网页有标题:

<script src="/javascripts/jquery.js?1312437063" type="text/javascript"></script> 
<script src="/javascripts/jquery_ujs.js?1312437070" type="text/javascript"></script> 
<script src="/javascripts/application.js?1311268601" type="text/javascript"></script> 
<meta name="csrf-param" content="authenticity_token"/> 
<meta name="csrf-token" content="KdgrBxF726xfPP3qbNOHd/0TG9c7lVCoZDXPnadFOzI="/> 

Ajax 请求书的行文如下:

<%= link_to  Run , :controller => "config_panel", :action => "full_run", :remote => true, :format => :js %>

声明如下:

<a href="/config_panel/full_run.js?remote=true">Run</a>

控制器定义的反应:

def full_run
  respond_to do |format|
    format.js { render :text => "alert();"}
    format.xml
  end
end

在被点击时,服务器标识:

Started GET "/config_panel/full_run.js?remote=true"
Processing by ConfigPanelController#full_run as JS
Parameters: {"remote"=>"true"}
Rendered text template (0.0ms)
Completed 200 OK in 1ms (Views: 0.6ms | ActiveRecord: 0.0ms)

浏览器显示平原:

alert();

传真机有<代码>status:200和content-type:text/javascript。 Chrome·贾科特·科索尔没有错误。

我尝试了以下工作:

  • include rails.js --- failed
  • change link_to to <div onclick="$.ajax(...)"> --- worked

I m 受到<代码>:remote =>的行为的困惑 页: 1

问题回答

为此:

<%= link_to  Run , { :controller => "config_panel", :action => "full_run" }, :remote => true %>

如果你使用路线帮助器,就必须把路器当作头盔。

link_to reference





相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签