1

I have a ajax call to a controller that checks for authentication, when no authentication exists it sends the call onwards to the signin controller who checks if it is a xhr request. If it is it renders an rjs containing a page.redirect_to to the signin path and the main window is redirected to the signin page. This works flawlessly in google chrome but fails in Firefox.

the only code in the rjs file is:

page.redirect_to("http://localhost:3000/signin")

As i said, it works flawlessly in chrome but Firefox(v3.6) refuses to redirect the main Window. Does anyone have any ideas as to how i can get this to work in Firefox as well?

nenne
  • 165
  • 2
  • 9
  • possible duplicate of [How can I make a redirect page in jQuery/JavaScript?](http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-in-jquery-javascript) – fotanus Sep 02 '13 at 20:21

2 Answers2

1

Are there any errors appearing in the console?

Would it not be easier to respond to "js" and render a js template with something like:

window.location = "http://localhost:3000/signin"

On a bit of a tangent, should you really be redirecting to "localhost:3000" absolutely anyway? Maybe there is a different solution?

Blake Simpson
  • 1,078
  • 6
  • 10
  • Im using that url only as a placeholder while developing, but since page.redirect_to generates window.location.href i dont think it will make much of a difference using that approach. – nenne Aug 16 '11 at 10:35
  • I dont seem to find any errors in the console either im afraid. – nenne Aug 16 '11 at 10:39
1

You will probably need to handle the response from the ajax request and redirect via JavaScript:

window.location = urlToDirectTo;

I think most browsers will redirect the ajax request itself, not the page from which the ajax request was made. Here's an answer to a similar question that details the solution.

Community
  • 1
  • 1
Spycho
  • 7,698
  • 3
  • 34
  • 55
  • page.redirect_to generates the javascript gode window.location.href so i dont believe it will make much of a difference. Weird thing is i couldnt even get a alert('hello'); to show up. I dont think firefox is letting the javascript to reach the main window. – nenne Aug 16 '11 at 10:34
  • I seem to get a 304 which would indicate an empty response? That seems weird. But maybe it just redirects the ajax frame and returns nothing to the main window? – nenne Aug 16 '11 at 10:59
  • 304 indicates "not modified". That would imply that it's caching... You might want to take a look at your request / response headers. You can view them in Firebug in Firefox. – Spycho Aug 16 '11 at 11:03
  • 1
    I finally managed to solve it: The problem was basicly that i redirected once before i executed the javascript redirect. Firefox apparently didnt like that extra redirect while the webkit browsers didnt seem to mind. Moving the javascript window.location 1 step up in the chain solved the problem. (So basicly the javascript is called in the auth method of the application controller instead of redirecting to signin where i called it earlier) Thanks for all the input! – nenne Aug 16 '11 at 12:00