Note that there are some explanatory texts on larger screens.

plurals
  1. PORedirect within Ajax call
    primarykey
    data
    text
    <p>I need to redirect an Ajax call without letting the client know.</p> <p>getPage.php is an application which returns html etc. for a given query.</p> <p><strong>getPage.php?hash=interesting-article-title</strong> and <strong>getPage.php?page=3</strong> returns the same.</p> <p>To avoid the client from having to cache both of these I would like <strong>getPage.php?hash=interesting-article-title</strong> to REDIRECT to <strong>getPage.php?page=3</strong> via PHP header 301 and location.</p> <p>I tried doing this and it returns nothing. The ajax call does not seem to want to be redirected.</p> <p>Does anyone have any idea what could solve this double-cache problem?</p> <p>I would like to use 301 redirects because they are cacheable. This way the browser would automatically call <strong>page=3</strong> when it is told to fetch <strong>hash=insteresting-article-title</strong>.</p> <p>Code examples: </p> <pre><code> function handleInit(event) { if (event.path != "/") { var hash = event.path.replace(/\//,"").replace(/\?/g,""); getPage(hash); currentState.hash = hash; } else { currentState.id = 1; } SWFAddress.addEventListener(SWFAddressEvent.CHANGE, handleChange); } function chapter_forward() { if (!freeze) { freeze = true; getPage(currentState.id - 1); } } function ajax_data(id) { return typeof(id) == "string" ? "hash=" : "page="; } function getPage(id) { $.ajax({ method: "get", url: getPage.php, data: ajax_data(id) + id.toString(), dataType: 'json', timeout: 2000, error: function() { $("#space-3").html('40104 - Request Timeout'); }, complete: function() {}, success: function(result) { handleContent(result); } }); } </code></pre> <p></p> <p>The reason I need the redirect to happen is because I get the id from a HASH when the user uses his back and forth browser buttons.</p> <p>When the user simply navigates back and forth I simply add +1 to the current id.</p> <p>getPage.php returns something like this:</p> <pre><code>{"article_id":"3","hash":"music-in-your-ear","title":"Music in your ear.","html":"Blah blah article 3","modified":"Fri, 20 Mar 2009 02:46:00 GMT"} </code></pre> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload