Page redirect with successful Ajax request?

Sure. Just put something at the the end of your success function like: if(result === "no_errors") location. Href = "example.com/ThankYou.html where your server returns the response no_errors when there are no errors present.

Sure. Just put something at the the end of your success function like: if(result === "no_errors") location. Href = "example.com/ThankYou.html" where your server returns the response no_errors when there are no errors present.

Proper usage of HTTP Status Codes will make every success a success without the server having to pass back any messages. – Jeremy Aug 18 '10 at 15:57 @Jeremy- True, unless you wanted to pass back specific error messages for the site to deal with or even different URLs to redirect to on failure. Those messages would have to be returned with a 200 response code necessitating a no_errors response to differentiate.

– Adam Aug 18 '10 at 16:13 Actually from first look it would seem to me that this method would work! – Amit Aug 18 '10 at 16:33 Is it possible to GET the $error variable returned from the mail3. Php file (see EDIT) and check for its content.

If!($error), then redirect page? – Amit Aug 18 '10 at 16:40 @Adam - Not necessarily. The error function in jQuery's Ajax object will still have access to the response text of the response.

– Jeremy Aug 18 '10 at 18:34.

You can just redirect in your success handler, like this: window.location. Href = "thankyou. Php"; Or since you're displaying results, wait a few seconds, for example this would wait 2 seconds: setTimeout(function() { window.location.

Href = "thankyou. Php"; }, 2000).

I only want it to be redirect to thankyou. Php if no errors are present. – Amit Aug 18 '10 at 16:39 @Amit - You could put if(result === "Your message was successfully sent!

") before this, that would only send in those cases. – Nick Craver? Aug 18 '10 at 16:58.

Just do some error checking, and if everything passes then set window. Location to redirect the user to a different page. $.

Ajax({ url: 'mail3. Php', type: 'POST', data: 'contactName=' + name + '&contactEmail=' + email + '&spam=' + spam, success: function(result) { //console. Log(result); $('#results,#errors').remove(); $('#contactWrapper').

Append('' + result + ''); $('#loading'). FadeOut(500, function() { $(this).remove(); }); if ( /*no errors*/ ) { window. Location='thank-you.

Html' } } }).

How can I check for no errors condition if all of the errors are processed through the mail3. Php file? – Amit Aug 18 '10 at 15:58 1 you should trap errors in your mail3.

Php file, and return a status code of 500 on your response. – Jeremy Aug 18 '10 at 16:03 Could you elaborate a little? How exactly do I return this status code of 500?

– Amit Aug 18 '10 at 16:32 Is it possible to GET the $error variable returned from the mail3. Php file (see EDIT) and check for its content. If!($error), then redirect page – Amit Aug 18 '10 at 16:40 1 @Amit I would do something like if(result === "Your message was successfully sent!")//redirect else $('#id ofEmptyDivOnPage').

Html(response) that'll display the errors on the page if there are errors and redirect if not assuming you have a div with that id – Adam Aug 18 '10 at 16:46.

I think you can do that with: window. Location = "your_url.

I suppose you could attack this in two ways; 1) insert window. Location = 'yourdomain.com into the success function. 2) Use a further ajax call an inject this into an element on your page, further info on which you can find in the jQuery docs at api.jquery.com/jQuery.get.

In your mail3. Php file you should trap errors in a try {} catch {} try { /*code here for email*/ } catch (Exception $e) { header('HTTP/1.1 500 Internal Server Error'); } Then in your success call you won't have to worry about your errors, because it will never return as a success. And you can use: window.location.

Href = "thankyou. Php"; inside your success function like Nick stated.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions