简体   繁体   中英

Rails ajax partial issue

I have a homepage that calls out to an xml feed using jquery ajax. It takes a couple seconds to get the feed. I'd like users to be able to navigate away from the page before the ajax call is done.

JS:

$(document).ready(function() {
 $.ajax({
   dataType: 'html',
   url: '/home/get_feed'
 }).done(function(data){
   $('#feed_data_area').html(data);
 });
});

Controller:

def get_feed
 @feed = Feedjira::Feed.fetch_and_parse('http://www.genericwebservice.com/feed')

 render :partial => 'feed_data', :locals => {:feed => @feed}
end

Is this something I have to do in the js, or is there a rails way to interrupt the controller?

Thanks for any help.

Do you mean to abort the ajax call? and/or ask rails to stop?

Here is a post regarding aborting: Abort Ajax requests using jQuery

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