cant return value out of closure
<p>I cant seem to get this value to pass the isValid value back out of the ajax call in the snippet below:</p>

<pre><code>    function isShortUrlAvailable(sender, args) {
        var isValid = false;
        $.ajax({
            type: "POST",
            url: "/App_Services/ShortUrlService.asmx/IsUrlAvailable",
            data: "{url: '" + args.Value + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                isValid = response.d;
            },
            error: function (msg) {
                isValid = false;
            }
        });

        args.IsValid = isValid;
    }
</code></pre>

<p>I'm sure its just something simple to do with closures that i'm overlooking. Can anyone help please?</p>

<p>Its for an asp.net custom validator. </p>

<p>This is what's happening:</p>

<ol>
<li>isValid is set to false in the first line</li>
<li>.ajax() request fires correctly and if its valid returns true</li>
<li>isValid is set to true (response.d) correctly</li>
<li>when it comes back out to the last line it thinks isValid is false again</li>
</ol>
