asked on
var $text = runUsernameAjax('CheckUsername', 'username', $("#<%=UsernameTextbox.ClientID%>").val());
alert($text);
function runUsernameAjax(webmethod, fieldname, fieldtext) {
//alert('in ajax method' + webmethod + ":" + fieldname + ":" + fieldtext);
$(function () {
$.ajax({
type: "POST",
url: "default.aspx/CheckUsername",
data: JSON.stringify({ username : fieldtext }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
if (data) {
$text = "Congratulations " + fieldtext + " is available.";
//return text;
}
else {
alert("Unfortunately " + fieldtext + " is not available.");
return "Unfortunately " + fieldtext + " is not available.";
}
},
error: function (xhr, ajaxOptions, thrownError) {
return thrownError;
}
});
});
}
function runUsernameAjax(webmethod, fieldname, fieldtext) {
//alert('in ajax method' + webmethod + ":" + fieldname + ":" + fieldtext);
$(function () {
$.ajax({
type: "POST",
url: "default.aspx/" + webmethod,
data: JSON.stringify({ fieldname : fieldtext }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
if (data) {
$text = "Congratulations " + fieldtext + " is available.";
//return text;
}
else {
alert("Unfortunately " + fieldtext + " is not available.");
return "Unfortunately " + fieldtext + " is not available.";
}
},
error: function (xhr, ajaxOptions, thrownError) {
return thrownError;
}
});
});
}