Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何将JSON响应插入到div中?_Ruby On Rails_Ruby_Json - Fatal编程技术网

Ruby on rails 如何将JSON响应插入到div中?

Ruby on rails 如何将JSON响应插入到div中?,ruby-on-rails,ruby,json,Ruby On Rails,Ruby,Json,我的视图中有一个,我需要在按下按钮后用一些信息更新它。My函数返回JSON格式的信息,如下所示: <%= button_to "Ping", {:action => :ping_server}, :method => :get, :remote => true %> 如何将返回的值插入位于servers/server.show.html.erb的div中 <div id="pingDiv"> </div> 您希望绑定到ajax:suc

我的视图中有一个
,我需要在按下按钮后用一些信息更新它。My函数返回JSON格式的信息,如下所示:

<%= button_to "Ping", {:action => :ping_server}, :method => :get, :remote => true  %>
如何将返回的值插入位于servers/server.show.html.erb的div中

<div id="pingDiv">

</div>

您希望绑定到
ajax:success
ajax:error
挂钩。有关远程表单如何工作的更多详细信息,请查看“”

$("#some_form_id").on("ajax:success", (e, data, status, xhr) ->
  $("#pingDiv").append xhr.responseText
).bind "ajax:error", (e, xhr, status, error) ->
  $("#pingDiv").append "<p>ERROR</p>"
$(“#某种形式的_id”)。关于(“ajax:success”,(e,数据,状态,xhr)->
$(“#pingDiv”)。追加xhr.responseText
).bind“ajax:error”(e,xhr,status,error)->
$(“#pingDiv”)。追加“错误”
$("#some_form_id").on("ajax:success", (e, data, status, xhr) ->
  $("#pingDiv").append xhr.responseText
).bind "ajax:error", (e, xhr, status, error) ->
  $("#pingDiv").append "<p>ERROR</p>"