title: How to redirect to another page after ajax success
body: <p>Below i have a ajax request that is suppose to redirect to another page if successful but i cannot get it to redirect at all even when there are no errors at all.  I have been at this for 10 hours any help is greatly appreciated</p>
  
  <pre><code>            var $form = $('#payment-form');
  
              function showErrorDialogWithMessage(message){
                  $('#payment-error').removeClass('hidden').addClass('error').append(message);
              }
  
              function stripeResponseHandler(status, response){
                  if (response.error) 
                  {
                      // Stripe.js failed to generate a token. The error message will explain why.
                      // Usually, it's because the customer mistyped their card info.
                      // You should customize this to present the message in a pretty manner:
                      $('#payment-error').removeClass('hidden').addClass('error').append(response.error.message); //Throw relevant error
                  } 
                  else 
                  {   
                      // Stripe.js generated a token successfully. We're ready to charge the card!
                      var token = response.id;
                      $form.append($('&lt;input type="hidden" name="stripeToken" /&gt;').val(token));
  
                      // Make the call to the server-script to process the order.
                      // Pass the token and non-sensitive form information.
                      var request = $.ajax({ //Process the form using $.ajax()
                          type        : 'POST', //Method type
                          url         : 'charge.php', //Your form processing file url
                          dataType    : 'json',
                          data        : $form.serialize(), //serialize form
                          success     : function(data) {
                              if(data.success == true){
                                  window.location.replace("http://weloveapp.co.uk/portal/push.php");
                              }
                          }
                      });
                  }
              }
  
              jQuery( document ).ready(function($) {
  
                  $form.submit(function(event) { //Trigger on form submit
                      $('.error').empty(); //Clear the messages first
  
                      var emailAddress = $('.emailAddress').val();
                      var name = $('.name').val();
                      var cardNumber = $('.creditnumber').val();
                      var cardCVC = $('.creditcvc').val();
  
                      // Validate the email address:
                      var emailFilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  
                      if (emailAddress === "") {
                          showErrorDialogWithMessage("Please enter your email address.");
                      } else if (!emailFilter.test(emailAddress)) {
                          showErrorDialogWithMessage("Your email address is not valid.");
                      }
  
                      if (name === "") {
                          showErrorDialogWithMessage("Please enter your name.");
                      }
  
                      // Stripe will validate the card number and CVC for us, so just make sure they're not blank
                      if (cardNumber === "") {
                          showErrorDialogWithMessage("Please enter your card number.");
                      }
                      if (cardCVC === "") {
                          showErrorDialogWithMessage("Please enter your card security code.");
                      }
  
  
                      // createToken returns immediately - the supplied callback submits the form if there are no errors
                      Stripe.createToken({
                          number: $('.creditnumber').val(),
                          cvc: $('.creditcvc').val(),
                          exp_month: $('.creditexpiremonth').val(),
                          exp_year: $('.creditexpireyear').val()
                      }, stripeResponseHandler);
  
                      event.preventDefault(); //Prevent the default submit
                  });
  
              });
  
                  &lt;?php
              require_once('stripe-payment/init.php');
              require_once('../wp-config.php');
              global $wpdb;
  
              $errors  = array();     // array to hold validation errors
              $form_data = array();       // array to pass back data
  
              $adminemail = 'hello@weloveapp.com';
  
              $emailAddress = $_POST['emailAddress'];
              $name = $_POST['name'];
              $creditnumber = $_POST['creditnumber'];
              $creditcvc = $_POST['creditcvc'];
              $creditexpiremonth = $_POST['creditexpiremonth'];
              $creditexpireyear = $_POST['creditexpireyear'];
  
              if(!$emailAddress){
                  $errors['emailAddress'] = 'Please enter an email';
              }
              elseif(!$name){
                  $errors['name'] = 'Please enter your name';
              }
              elseif(!$creditnumber){
                  $errors['creditnumber'] = 'Please enter credit card number';
              }
              elseif(!$creditcvc){
                  $errors['creditcvc'] = 'Please enter cvc';
              }
              elseif(!$creditexpiremonth){
                  $errors['creditexpiremonth'] = 'Please enter expire month';
              }
              elseif(!$creditexpireyear){
                  $errors['creditexpireyear'] = 'Please enter expire year';
              }
  
              // if there are any errors in our errors array, return a success boolean of false
              if (!empty($errors)) {
  
                  // if there are items in our errors array, return those errors
                  $form_data['success'] = false;
                  $form_data['errors']  = $errors;
              } else {
  
                  try {
                      \Stripe\Stripe::setApiKey('sk_test_CdOuItKDV4I42DFK4ehTg9Xo');
                      // $myCard = array('number' =&gt; '4242424242424242', 'exp_month' =&gt; 5, 'exp_year' =&gt; 2016);
                      $myCard = array('number' =&gt; $_POST['cardnumber'], 'exp_month' =&gt; $_POST['creditexpiremonth'], 'exp_year' =&gt; $_POST['creditexpireyear']);
                      $token = htmlspecialchars($_POST['stripeToken']);
                      $total_amount = '3.99';
                      $total_amount = $total_amount*100;
  
                      $charge = \Stripe\Charge::create(array(
                      'amount' =&gt; $total_amount, 
                      'currency' =&gt; 'GBP', 
                      'card' =&gt; $token
                      ));
  
                      //setcookie($cookie_name, $cookie_value, time()+86400); // 86400 = 1 day                        
  
                      $ipaddress = $_SERVER['REMOTE_ADDR'];
  
  
                      $result = $wpdb-&gt;get_var( "SELECT ip FROM push WHERE ip='$ipaddress'");
  
  
                      if($result == $ipaddress){
                          $wpdb-&gt;update( 'push', 
                              array( 'date' =&gt; date('Y-m-d')  ),
                              array( 'ip' =&gt; $ipaddress ), 
                              array( '%s' )               
                          );
  
                      } else {
                          $wpdb-&gt;insert( 'push', array(
                              'ip' =&gt; $cookie_name, 
                              'date' =&gt; date('Y-m-d'),
                              'status' =&gt; $cookie_value ),
                              array( '%s', '%s', '%s' ) 
                          );
                      }
  
  
                      $msg="Hello ".$name.","
                                  . "&lt;br&gt; &lt;br&gt;We have received the payment, you can now access push notifications."
                                  . "&lt;br&gt; Thanks,";
  
                      $headers = 'From: We Love APP &lt;hello@weloveapp.co.uk&gt;' . "\r\n" .
                      'Reply-To: hello@weloveapp.com' . "\r\n" .
                      'X-Mailer: PHP/' . phpversion();
  
                      $headers .= "MIME-Version: 1.0\r\n";
                      $headers .= "content-type: text/html\r\n";
  
                      mail($emailAddress, 'Payment successful', $msg, $headers);
  
                      $msg="Hello Admin,"
                                  . "&lt;br&gt; &lt;br&gt;You have received a new payment for push notifications"
                                  . "&lt;br&gt; Thanks,";
  
                      $headers = 'From: New Push Notification Payment' . "\r\n" .
                      'Reply-To: ' .$emailAddress.' ' . "\r\n" .
                      'X-Mailer: PHP/' . phpversion();
  
                      $headers .= "MIME-Version: 1.0\r\n";
                      $headers .= "content-type: text/html\r\n";
  
                      mail($adminemail, 'You have received a new payment for push notifications', $msg, $headers);
  
                      // show a message of success and provide a true success variable
                      $form_data['success'] = true;
                      $form_data['posted']='We have received your payment.';  
                  }
                  catch(Exception $e){
                      $errors['key']='danger';
                      $errors['msg'] = $e-&gt;getMessage();
  
                      $form_data['success'] = false;
                      $form_data['errors']  = $errors;
                  }
              }
              // return all our data to an AJAX call
              echo json_encode($form_data);
              ?&gt;
  </code></pre>