title: pass URL built in php as json to ajax for opening in new tab
body: <p>how to return URL built in php as json object to ajax to open it in the new tab?</p>
  
  <p>so far all my attempts to do so were unsuccessful. Please help</p>
  
  <p>here is my JS file</p>
  
  <pre><code>$(document).ready ( function() {
  
      $('.promoCode').click(function() {
  
          // Store values in variables
          var form = $(this).closest('form');
          var name = form.find('input[name=name]');
          var id = form.find('input[name=id]');
          var submitted = form.find('input[name=submitted]');
          var visitor = form.find('input[name=visitor]');
  
          // Organize data
          var data = 'name=' + name.val() + '&amp;id=' + id.val() + '&amp;submitted=' + submitted.val() + '&amp;visitor=' + visitor.val();
  
          var request = $.ajax({
              type: "POST",
              url: "/includes/_db_get_promo_code.php",
              data: data,
              cache: false,
              success: function (html) {
                  myWindow = window.open(encodeURIComponent(true),
                      "_blank");
                  myWindow.focus();
                  if (html == "true") {
  
                  } else {
                          form.find('.error').fadeIn(500).delay(4000).fadeOut(500);
                  }
              },
              error: function(jqXHR, textStatus, error) {
  
                  alert("Form Error: " + error);
              }
          });
          return false;
      });
  });
  </code></pre>
  
  <p>and here is my PHP file</p>
  
  <pre><code>&lt;?php
  require_once($_SERVER['DOCUMENT_ROOT']."/includes/sitewide-variables.php");
  // Check if form was submitted
  if ($_POST['submitted'] &amp;&amp; $_POST['visitor'] == '') {
  
      // Check if all required fields are filled in
      if (empty($_POST['name']) &amp;&amp; empty($_POST['id'])) {
          echo "Error: You must fill in all required fields.";
          // If not, exit!
          exit();
      }
      // If valid, store values in variables
      $id = stripslashes($_POST['id']);
      $name = stripslashes($_POST['name']);
  
  if($name){
      $query = 'SELECT * FROM files_paid WHERE parentpageID = :promoproductID';
      $res = $db-&gt;prepare($query);
      $res-&gt;execute(array(':promoproductID' =&gt; $id));
      foreach ($res as $info);
  
      if($info['promoCode'] == $_POST['name']){
          $redirect_link = 'http://'.$info['promobuylinkID'].'.myid.pay.clickbank.net';
  
      $todayis = date("l, F j, Y, g:i a") ;
      $to = "My Email Address";
      $subject = "Promotional Purchase";
      $message = "$todayis [EST] \n
                  Promo Code: $name \n
                  ";
      // Send email
      $sent = mail($to, $subject, $message);
  
      if($sent) {
          echo json_encode($redirect_link);
  
      } else {
          echo "Error: Mail could not be send.";
          exit();
      }
  } else {
      echo "Error: There was a problem with submitting the form";
      exit();
  }
  }
  }
  ?&gt;
  </code></pre>
  
  <p>I am only getting <code>true</code> in the new window.</p>
  
  <p>Thanks in advance</p>