rv20 Posted May 24, 2009 Share Posted May 24, 2009 If you are running to a php script through ajax well i have just discovered that you can't redirect from within the script, if you do say a header("location: index.php"); then what happens is that the index.php source is (in my case) injected into the page i am using ajax from, which makes sense as that is how ajax works! So i guess there is no way to switch from ajax back to http while in the middle of a php script that ajax is communicating with. I know i can parse the ajax response from within the JS and use something like, window.location = parsed response; but this seems really messy and almost novice like and plus it exposes some of your code. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/159435-how-to-php-redirect-when-using-ajax/ Share on other sites More sharing options...
Ken2k7 Posted May 24, 2009 Share Posted May 24, 2009 PHP - echo 'redirect_url'; JavaScript - window.location.href = ajax.responseText; Quote Link to comment https://forums.phpfreaks.com/topic/159435-how-to-php-redirect-when-using-ajax/#findComment-841054 Share on other sites More sharing options...
rv20 Posted May 24, 2009 Author Share Posted May 24, 2009 PHP - echo 'redirect_url'; JavaScript - window.location.href = ajax.responseText; I know what your doing but would you regard this as a good way of doing things it just seems that it is, 1) messy 2) novice 3) More overhead 4) possible secuirty holes ?? maybe not. Quote Link to comment https://forums.phpfreaks.com/topic/159435-how-to-php-redirect-when-using-ajax/#findComment-841057 Share on other sites More sharing options...
Ken2k7 Posted May 24, 2009 Share Posted May 24, 2009 1. Not messy. Two simple lines. 2. Not novice. Simple yes. The simpler the better. Why make it complicated when you don't have to. 3. What? 4. You're using JavaScript. But you should be fine. Quote Link to comment https://forums.phpfreaks.com/topic/159435-how-to-php-redirect-when-using-ajax/#findComment-841060 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.