我有这个函数来检查子域是否存在并且它工作正常,这里唯一的问题是我希望它返回false(如果它存在)并且如果它没有则返回true。
这是我的代码:
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;
}
谢谢!