My requirement is like to check whether the app name is already used or not using Ajax. I achieved those things , I planned to add those things in jquery validation. I added that using add method but if the response is false
it shows the message
app name exists
error message. And also if the response is true
it shows the error message as well.
Here's my code:
$(document).ready(function ()
{
function isAppNameExists() {
document.getElementById('imgLoad').style.display = "inline-table";
var appName =$("#txtAppName").val();//document.getElementById("txtAppName").value;
var tenantID =1;//document.getElementById("txttenantId").value;
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if(xmlhttp.readyState==4 && xmlhttp.status==200){
if(xmlhttp.responseText == "true"){ // App name already used
document.getElementById('imgLoad').style.display = "none";
return false;
} else {
document.getElementById('imgLoad').style.display = "none";
return true;
}
}
}
xmlhttp.open("GET","ApplicationController?appNameCheck=createApp&appName="+appName+"&tenantId="+tenantID+"",true);
xmlhttp.send();
}
$.validator.addMethod("appNameExistsValidation", function() {
return isAppNameExists();
}, "Application name already exists");
$('#storeAppCreation').validate(
{
rules:
{
appNameExistsValidation:true
}
}
});