简体   繁体   English

Rails-jQuery / AJAX不刷新部分内容

[英]Rails - jQuery/AJAX not refreshing partial

I've got a timeline view that shows partials for events - so you can CRUD events directly on the timeline view. 我有一个显示事件部分的时间轴视图-因此您可以直接在时间轴视图上CRUD事件。 What I'm now trying to do is to have it so that when you click 'delete' next to an event, the delete partial refreshes, so that the user can see that the event has been deleted. 我现在想要做的就是拥有它,以便当您单击事件旁边的“删除”时,删除部分会刷新,以便用户可以看到该事件已被删除。 I can't seem to get this to work - the event does get deleted when the user clicks delete, but the partial doesn't refresh. 我似乎无法使它正常工作-当用户单击“删除”时,事件确实被删除,但部分内容不会刷新。 You have to refresh the page to get the updated partial. 您必须刷新页面以获取更新的部分内容。

Also, please can someone tell me how I would request the updated contents of the "my-timeline" div, so that the deleted event doesn't appear in there too? 另外,请有人告诉我我将如何请求“我的时间轴” div的更新内容,以便删除的事件也不会在那里出现? Thanks! 谢谢!

timeline/show: 时间轴/节目:

<div id="my-timeline"></div>
<div id="delete_events">
    <%= render :partial => "delete_events", :locals => { :events => current_user.events }%>     
</div>

timeline/_delete_events.html.erb: 时间轴/_delete_events.html.erb:

<%= button_to 'Delete', event, confirm: "Are you sure?", method: :delete, :remote => true %>

events/delete.js.erb: events / delete.js.erb:

$('#delete_events').html('<%= escape_javascript( render :partial => "/timelines/delete_events", :locals => { :events => current_user.events } ) %>');

events controller: 事件控制器:

def destroy
    @event = Event.find(params[:id])
    @event.destroy

    respond_to do |format|
      format.html { redirect_to current_user.timeline, notice: 'Event was successfully removed.' }
      format.json { head :no_content }
      format.js
    end
  end

The javascript for generating the timeline (only located here temporarily!) into the my-timeline div: 用于将时间轴(仅临时位于此处!)生成到我的时间轴div中的javascript:

<script>
            $(document).ready(function() {
                createStoryJS({
                    type:       'timeline',
                    width:      '820',
                    height:     '600',
                    source:     '/users/<%= current_user.id %>/events.json?callback',
                    embed_id:   'my-timeline',
                    font:       'Euphoria-Droid',
                    debug:      true,
                    gmap_key:   'foo',
                    maptype:    'HYBRID'
                });
            });
        </script>

i think you should change name from 我认为你应该把名字从

  events/delete.js.erb

    to

 events/destroy.js.erb

and by write alert("ok") in destroy.js.erb check control comes here 并通过在destroy.js.erb中编写alert(“ ok”)来检查控件

Hope it works 希望能奏效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM