Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Send form to .php, prevent redirection with ajax

9:32 am on Aug 12, 2011 (gmt 0)

New User

5+ Year Member

joined:Aug 12, 2011
votes: 0

I have a form which action is a php script.
That script returns a header('Location: whatever.html');

Now my question is, would be a way through ajax/javascript to do that only the form were sent, but avoid or prevent the redirection to whatever.html? Also, if would be possible know the page where I was going redirected to... but this is secondary, and I'm asking too much.

I've tried with:

var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
if (xmlhttp.readyState==4 && xmlhttp.status==200)


But in the alert it doesn't give me any Location.

Hope you can understand me.
Thanks in advance.
8:20 am on Aug 30, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:July 8, 2010
posts: 114
votes: 0

It wont work...

quote from w3 ( [w3.org...] ):

If the response is an HTTP redirect (status code 301, 302, 303 or 307), then it MUST be transparently followed (unless it violates security or infinite loop precautions). Any other error (including a 401) MUST cause the object to use that error page as the response.

So it seems it's impossible to catch the redirect...

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members