Ajax 轮询:不显示警告框 [rails]
Ajax polling: Doesn't display alert box [rails]
按照 railscast ajax 轮询教程(#229)实施 ajax 轮询。 运行 服务器后不会弹出警告框。
app/views/quotes/index.js.erb:
alert('Hey');
QuotePoller.poll();
app/assets/javascrips/quotes.咖啡:
@QuotePoller =
poll: ->
setTimeout @request, 1000
request: ->
$.get($('#quotes').data('url'))
jQuery ->
if $('#quotes').length > 0
QuotePoller.poll()
app/views/quotes/index.html.erb:
<div id="quotes" data-url="<%= quotes_url %>">
<table>
<thead>
<tr>
<th>Content</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @quotes.each do |quote| %>
<tr>
<td><%= quote.content %></td>
<td><%= link_to 'Show', quote %></td>
<td><%= link_to 'Edit', edit_quote_path(quote) %></td>
<td><%= link_to 'Destroy', quote, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
您需要在app/assets/javascripts/application.js中添加如下代码:
$(function() {
$.getScript("/quotes.js");
});
弹出窗口将出现在 localhost:3000/quotes。
通过将此添加到我的索引操作来解决它
app/controllers/quotes_controller.rb:
respond_to do |f|
f.js { render :content_type => 'text/javascript' }
f.html
end
按照 railscast ajax 轮询教程(#229)实施 ajax 轮询。 运行 服务器后不会弹出警告框。
app/views/quotes/index.js.erb:
alert('Hey');
QuotePoller.poll();
app/assets/javascrips/quotes.咖啡:
@QuotePoller =
poll: ->
setTimeout @request, 1000
request: ->
$.get($('#quotes').data('url'))
jQuery ->
if $('#quotes').length > 0
QuotePoller.poll()
app/views/quotes/index.html.erb:
<div id="quotes" data-url="<%= quotes_url %>">
<table>
<thead>
<tr>
<th>Content</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @quotes.each do |quote| %>
<tr>
<td><%= quote.content %></td>
<td><%= link_to 'Show', quote %></td>
<td><%= link_to 'Edit', edit_quote_path(quote) %></td>
<td><%= link_to 'Destroy', quote, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
您需要在app/assets/javascripts/application.js中添加如下代码:
$(function() {
$.getScript("/quotes.js");
});
弹出窗口将出现在 localhost:3000/quotes。
通过将此添加到我的索引操作来解决它
app/controllers/quotes_controller.rb:
respond_to do |f|
f.js { render :content_type => 'text/javascript' }
f.html
end