1
有一個奇怪的問題,試圖通過rails中的AJAX更新搜索結果,在rails中將js.erb加載到頁面上原始文本的<pre>
標記中,並且不會觸發任何js文件。js.erb渲染文本不是JS
if request.format.js?
respond_to do |format|
format.js { render layout: false }
end
end
形式設置火災AJAX與遠程:真正
= form_tag(search_path, id: "form", remote: true, :'data-type' => 'script') do
index.je.erb
alert('hello');
$("#results").innerHTML("<%= escape_javascript(render partial: 'results', locals: { results: @results }) %>");
的routes.rb
match 'search', to: 'properties#index', via: :post, defaults: { format: 'js' }
在路由中,我嘗試過強制js,因爲之前它是JSON,但沒有區別。 從日誌中,控制器接收JS的請求,但我得到這個在Chrome調試器:
(index):69 Resource interpreted as Document but transferred with MIME type text/javascript: "http://localhost:3000/search".
堅持一個alert("Js is working")
作品沒有問題,所以JS在那裏,射擊
林卡住,這應該是工作到現在爲止,我錯過了一些愚蠢的東西,還是我不知道的Rails 5中的新東西?
如果我可以提供任何更多的信息來幫助你halp我請問!
在此先感謝