views:

574

answers:

2

I have a Rails app that allows users to login via jQuery modal form. Once logged in, I refresh the original page using location.reload().

At this point, I'm attempting to create a new jQuery dialog. How can I open the dialog only after location.reload() has finished executing?

Right now the dialog is loading up before location.reload() is done. This is causing the dialog to disappear.

+2  A: 

You can't.

Calling location.reload() will reload the entire page. Once it's finished, the Javascript from the original page is completely gone.

If you're reloading the entire page anyway, what's the point of using AJAX in the first place?
You should perform the login using a regular postback, then add server-side code that emits Javascript to show the dialog in the login postback.

You could create a small popup window that uses window.opener to communicate with the original page after it reloads, but that's a very ugly idea and would be vulnerable to popup blockers.

SLaks
A: 

Perhaps you could try passing a variable through the url by appending ?var=value.

Then in your $(document).ready(function() { }); check for that parameter in the url and if it is there, execute jQuery's delay() function?

Not sure if this will work with Rails as I mostly do PHP & Drupal. Good luck!

Donovan Palmer