Question: SO I have a setup with a few links as follows

```
<a class="someclass" href="http://www.google.com" id="link01">Google</a>
<a class="someclass" href="http://www.yahoo.com" id="link02">Yahoo</a>
<a class="someclass" href="http://www.cnn.com" id="link03">CNN</a>
<a class="someclass" href="http://www.facebook.com" id="link04">Facebook</a>

$(".someclass").click(function() {
            var currentId = $(this).attr('id');
            var data = "do=clearthis&id=" + currentId;

              $.ajax({
                 type: "POST",
                  url: "clearance.php",
                  data: data,
                  success: function(msg){
                   }
                 });
               });
});

```

What I am doing is tking the link that is clicked, obtaining an id value from the link and ajax submitting that to my PHP file which will remove the link from my database.

So that when a user clicks on a link, that link is removed from my database. However, the problem is that its not actually working. I htink the problem is that its too fast, as jquery begins to POST that form for me, its already jumping to the target link. Is there any way to induce some kind of delay to allow my clearance.php to process the removal before allowing the user to continue to the target link?

THanks!

Answer: 
Make a synchronous AJAX request so that it completes first:

```
$.ajax({
  type: "POST",
  async: false,
  url: "clearance.php",
  data: data,
  success: function(msg){
  }
});

```
Another solution without making the request synchronous:

```
$(".someclass").click(function() {
    var currentId = $(this).attr('id');
    var data = "do=clearthis&id=" + currentId;
    var linkUrl =   $(this).attr("href");
        $.ajax({
             type: "POST",
                url: "clearance.php",
                data: data,
                success: function(msg){
                 },
                complete: function(){
                    window.location.href = linkUrl;
                }
             });
         });
    return false;
});

```