I have this function that checks if the subdomain exists or not and it works just fine, the only issue here is I want it to return false if it exist and and true if it doesn't.
Here's my code:
function subdomain_check(){
$('input[name=subdomain]').parent().removeClass("has-error has-feedback").removeClass("has-success has-feedback");
$('span.glyphicon').remove();
$(this).next('.help-inline').find('span').html($(this).val());
$(this).next('.help-inline').find('test').html("Votre URL ");
var subdomain = $('input[name=subdomain]').val();
if(subdomain == "" || subdomain.length < 4 || !isValidsubdomain( subdomain )){
$('input[name=subdomain]').parent().addClass( "has-error has-feedback" ).append("<span class='glyphicon glyphicon-remove form-control-feedback'></span>");
return false;
}else{
jQuery.ajax({
type: "POST",
url: "ajax.php",
data: 'subdomain='+ subdomain,
cache: false,
success: function(response){
if(response == 1){
$('input[name=subdomain]').parent().addClass( "has-error has-feedback" ).append("<span class='glyphicon glyphicon-remove form-control-feedback'></span>");
return false;
}else{
$('input[name=subdomain]').parent().addClass( "has-success has-feedback" ).append("<span class='glyphicon glyphicon-ok form-control-feedback'></span>");
return true;
}
}
});
}
};
ajax.php
$dirname = $_POST["subdomain"];
$filename = DOCUMENT_ROOT."sites/".$dirname;
if (is_dir($filename)) {
echo 1;
}else{
echo 0;
}
Thanks!