3
votes

In my Rails + Devise app I have a table of links to multiple "contacts", each being a simple jquery $.get AJAX request which calls Contact#show.

Inevitably after clicking anywhere from 3-25 of the links (successfully!), a request will fail (response status 0 or failed to load resource depending on browser), after which it will never work again until the browser tab is closed or cache is cleared.

Here's the javascript for the request

$.get('/contacts/1312')

Details...

  • I do have csrf_meta_tags at the top of my layout
  • The request heads do include a "X-CSRF-Token" with the correct CSRF token from the meta tag
  • On chrome, the failed requests do not show up in the server logs as a request. its as if they never made it. The only error reported is in the chrome console which reports a failure. This leads me to believe it is browser related.
  • On Safari, upon first failure, it seems to destroy the session any subsequent requests result in a request for the sign_in page, which leads me to believe it may have something to do with devise

Update 3/30/13: After looking at many of the related question on SO (this one: Rails not reloading session on ajax post), which have to do with CSRF not being set correctly, I dont believe this issue is related to CSRF because it works properly several times before it fails.

1
Seems like a weird edge case somewhere. Maybe use error callbacks on that .get() request and do a console.log for or something. .fail(function() { alert("error"); }) .always(function() { alert("finished"); });Phu Phan
@PhuPhan, thanks, any ideas on what I might console log out to get more details on why this is happening? There seems to be no discernable pattern between contacts that trigger the first fail.Austin Wang
I would look into time sensitive things like idling connections being dropped by the server? Or security tokens. Like if your security service kicks out idle users? Since AJAX may not count as real actions that keeps your connections alive. I believe the fail() and always() function has a parameters that you can print out. Let me go see. error Type: Function( jqXHR jqXHR, String textStatus, String errorThrown ) So try to print out the errorThrown and the textStatus with console.log().Phu Phan
@AustinWang Did you figure out what was wrong? I am having a similar issue.ayls
@ayls, yes i eventually did figure it out. I was using a feature datatables.js (a table library) that saved its state in the cookie. However, the data it was trying to save in the cookie exceeded the 4kb max, so my cookie was getting messed up , resulting in different behaviours across different browsers. I'd recommend seeing if anything is messing with your cookies and whether that's causing the issues.Austin Wang

1 Answers

0
votes

i eventually did figure it out. I was using a feature datatables.js (a table library) that saved its state in the cookie. However, the data it was trying to save in the cookie exceeded the 4kb max, so my cookie was getting messed up , resulting in different behaviours across different browsers.