I cant seem to get this value to pass the isValid value back out of the ajax call in the snippet below:
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;
}
I'm sure its just something simple to do with closures that i'm overlooking. Can anyone help please?
Its for an asp.net custom validator.
This is what's happening:
- isValid is set to false in the first line
- .ajax() request fires correctly and if its valid returns true
- isValid is set to true (response.d) correctly
- when it comes back out to the last line it thinks isValid is false again