how to replace html in application.html.erb using ajax in rails? -
I try Ajax inside yield, I work properly, but when I apply to ajax application.html.erb (Layout), then ezax is not working and not the place of HTML.
My application.html.erb:
& lt; Li id = "header_notification_bar" class = "dropdown" & gt; & Lt; An id = "click_notif" data-toggle = "dropdown" class = "dropdown-toggle" data-remote = "true" href = "#" & gt; & Lt; I class = "fa fa-bell-o" & gt; & Lt; / I & gt; & Lt; Span id = "notif_count" class = "badge bg-warning" & gt; & Lt; / Span & gt; & Lt; / A & gt; & Lt; Ul id = "notif_content" class = "dropdown menu extended notification" & gt; & Lt; / Ul & gt; & Lt; / Li & gt; & Lt; Script & gt; $ (Document) .ready (function () {$ ('# notif_content') .HTML ("& lt;% = j 'rendering' layout / load_notif '% & gt;"); $ ("# click_notif") Click (function () ($ ('# Notif_count'). Html ("& lt;% = j render 'layout / notif_count'% & gt;");});}); & Lt; / Script & gt;
If the application applies within the yield, the action should be added to the format.js
in the controller and I action_name.js.erb
, But what should I do in application.html.erb ???
Please help me,
You tried to do this Is:
$ (document) .ready (function () {$ ('# notif_content') .HTML ("& lt;% = j $ (document) .on (" click " , "#click_notif", function () {$ ('# notif_count'). Html ("& lt;% = j 'render' layout / load_notiff '%'; layout / notif_count '%> gt;");} Although;) Your question is quite unclear, you have a special problem with AJAX. That's because you're loading in DOM A element, JS event binders are not able to attach related events I do not imagine that the code written by me will work out of the box, but it basically depends on the principle - you have the "container" element , And appoint events from it
Because the container is present when the DOM loads, it means that you will be able to work with new elements.
Comments
Post a Comment