简体   繁体   中英

Rails 3.2 Coffeescript to Refresh Div using Ajax - Reloading entire page

So I need some help identifying why I am getting a fullpage refresh when I only want to refresh a div.

    #Div refresh, error on loading entire page and not just div - Need fix
      $.ajax success: (data) ->
      $("#auto").html data
     setTimeout executeQuery, 500

This is the coffeescript. The reference to

<div id="auto">

is on a partial. views/tasks/_console

routes file = match '/console', to: 'tasks/console#get'

I am getting the original page loaded, then a second full page loaded within the div. Not sure how to replace the original data with the refresh div. The goal is to refresh the view with the most current tasks that can be created by other users in the same program at other terminals.

Thanks for your help!

If you want to get html back from the rails action so that you can put it where you want it in the ajax success callback, you should do two things:

First, specify that you want html back from the rails action with dataType: "html"

Secondly, in your controller action, be sure not to render the layout. You just want the html for that specific action you are calling. Something like this:

respond_to do |format|
  format.html { render :layout => false }
end

These two things will ensure that your controller action renders the html response (but not the full page) and returns it as the response data to your original ajax call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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