Welcome Guest, Not a member yet? Register   Sign In
Forum Redirect Pages - How Do They Do It?
#1

[eluser]vanquish[/eluser]
I have a really slow section on my site that takes up to 10 seconds to fetch data from another server. I would really love to implement a "Thank you, please wait while we search" type redirect page functionally similar to the CodeIgniter forums. You know, the message you get when logging in, searching etc. An interstitial page helps the user know that the server is doing work, and not just bugging out.

I know this type of redirect is done with PHP, because I disabled Javascript and the redirect screen still showed.

I have a hunch this has something to do with output buffering, but I have almost no knowledge in this area.

If anyone has any ideas of how this type of thing is implemented, I'd greatly appreciate any insights!
#2

[eluser]Chad Fulton[/eluser]
Nope, it's not output buffering using PHP (although that would be neat, too). They're simply using a <meta> tag to instruct the browser to redirect the page after 1 second:

Code:
<meta http-equiv="refresh" content="1; url=http://ellislab.com/forums/search_results/.../">

In my opinion, it's not a very good way to do it, as I find it a pretty odd experience, to be buffeted from one page to the next without warning. Why not implement something using AJAX?
#3

[eluser]vanquish[/eluser]
Ah, unfortunately the meta redirect is completely unsuitable in my case, as the data will be returned within a variable timeframe of anywhere from 0.5 to 10 seconds. I never know exactly how long it will take.

Do you by any chance know of any tutorials or anything online that demonstrate an AJAX redirect system? We are already using JQuery and this would be the preferable framework to use.
#4

[eluser]Chad Fulton[/eluser]
I don't know of anything in particular which gives a demonstration or tutorial of this, but it shouldn't be too hard to pull off; it's a pretty simple application of AJAX in my opinion.

Of course, it requires that your users support Javascript, which isn't always ideal (I think that an output buffering solution would also likely require javascript, however, since when the data is eventually fetched, you'd want some way to clear the HTML which had been pushed to the browser with the "Please Wait" message, and that means Javascript).

I'm not sure what your page's flow is, so I'll make one up and hopefully it'll be helpful:

1. User initiates the long data fetch (clicks a button, or does a search, or whatever).
2. jQuery intercepts the button's default action and prevents it.
3. jQuery puts a little spinning icon and a "Please wait while your query is performed" message up on the page.
4. jQuery initiates an AJAX request with the server, to perform the request.
5. The spinning icon continues, and the "Please wait..." message remains on the screen while the server processes the query.
6. Here you have two options, depending on how you're doing this:
a) The server caches / stores the data in some way, and sends the appropriate URL back to jQuery, which redirects the page to that URL (i.e. the browser's URL changes)
b) The server returns the data, and jQuery puts it up on the current page (i.e. no page refresh)

Does this give you an idea?
If you haven't done anything with AJAX yet, there are a bunch of good tutorials on using jQuery to do it, and I have to say that jQuery makes it pretty simple.




Theme © iAndrew 2016 - Forum software by © MyBB