Jump to content

How to php redirect when using ajax


rv20

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.