title: Switch between Jquery AJAX and PHP with target="_blank"
body: <p>I have a search result displayed - in this there is an anchor tag like below.</p>
  
  <pre><code>&lt;div class="addfriend"&gt;
      &lt;a href="add_friend.php?from=kpkdhar22&amp;id=2" id="2" target="_blank" onclick="addfriend(1, 2)"&gt;Add as friend&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I was doing this because, I want to keep my search result. I dont want to do <code>POST</code>-<code>REDIRECT</code>-<code>GET</code> method. I was using AJAX to update friends nesting DB table. If I prevent default action on anchor tag, the link is being opened in the same page and redirected to <code>add_friend.php?from=kpkdhar22&amp;id=2</code> , DB is updated and when back is pressed search result page is giving error message and search is gone. I want to keep <code>target="_blank"</code> because in case JS is not enabled in browser, it will do in php.</p>
  
  <p>Can I execute the JS function other than anchor tag and still have a new tab.</p>
  
  <p>My AJAX code is like this :</p>
  
  <pre><code>function addfriend(fid, uid) {
      // uid --  person sending friends request
      // fid --  person receiving friends request
  
      var id = '#' + uid;
      $("id").parent().empty().addClass("friend").removeClass("addfriend").html("&lt;span&gt;Request sent&lt;/span&gt;");
  
      var userid   = uid;
      var friendid = fid;
      var status   = 'N';
  
      var dataString = 'userid=' + uid + '&amp;friendid=' + fid + '&amp;status=' + status;
  
      $.ajax({
          type   : "POST",
          url    : "js/add_friend.php",
          data   : dataString,
          cache  : true,
          success: function (html) {
              var id = '#' + uid;   // is this ok as selector
              $("id").parent().empty().addClass("friend").removeClass("addfriend").html("&lt;span&gt;Request sent&lt;/span&gt;");
          },
          error  : function () {
              $("#errors").html('');
              $("#errors").html('Failed to send your request.');
          }
      });
  }
  </code></pre>
  
  <p>When the function <code>addfriend(1,2)</code> is executed, a new tab is opened and in add_friend.php a JS alert message is displayed and I am closing that tab immediately. But AJAX success function is not executed, so I added the same before AJAX call, but that is also not worked.</p>
  
  <p>console message -- XHR finished loading: POST "<a href="http://localhost/bp1/js/add_friend1.php" rel="nofollow">http://localhost/bp1/js/add_friend1.php</a>".</p>
  
  <p>Please suggest me some process, or steps where am I going wrong. </p>
  
  <p>Regards,
  Poorna.</p>