0

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.

Gabe K
  • 133
  • 1
  • 7
  • Add this line on the `done` call: `console.log(data);` and post the output. – Hackerman Aug 12 '14 at 21:09
  • The output in the console is the html of the feed that populates the partial. Do you still want me to post it? I'd have to go through it and redact a bunch of stuff having to do with my company. – Gabe K Aug 13 '14 at 17:53

1 Answers1

0

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

Community
  • 1
  • 1
Andrew Madden
  • 73
  • 1
  • 5
  • Doesn't matter at this point. I just want users to be able to navigate away from the page if the ajax partial hasn't loaded yet. For the abort request, would I have to trigger that with any click on the page? I have some links that load other partials using ajax and I don't want those to interrupt the feed load. – Gabe K Aug 13 '14 at 17:47