How to ensure that a function is executed completely, before navigating to another page?
<p>I'm removing certain records using a webservice. The jquery ajax request is written in the onclick of a hyperlink. When im executing the script, line by line using firebug, it's getting removed otherwise it's not. Does any one meet any situation like this before? Please help</p>

<p>Code sample:</p>

<pre><code> $(".target").click(function() { 
            func();  //This function should be executed completely before navigating to another page
        });


 var func = function() {
            var items = $("#flag").find('td input.itemClass');
            id = items[0].value;
            var status = items[1].value;
            var type = items[2].value;
            var params = '{' +
                            'ID:"' + id + '" ,Type:"' + type + '" ,Status:"' + status + '"}';
            $.ajax({
                type: "POST",
                url: "WebMethodService.asmx/DeleteItem",
                data: params,
                //contentType: "plain/text",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {
                    $("#deleteNotificationMessage").val("Item has been removed"); // keep a separate label to display this message
                }

                //Event that'll be fired on Success

            });


    }
</code></pre>
