<?php
//header("Content-Type: content=text/html; charset=utf-8");
$section = isset($_POST['section'])?$_POST['section']:'start';
switch ($section){
case "start":
?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script>
$(document).ready(function()
{
function send_data(){
var nick_for_search= $('#nick_for_search').val();
$.post("test-user-nick.php", { nick_for_search: nick_for_search, section : 'search'},
function(data) {
if(data == 'error'){
$('#your_message_div').html('Неправильно введен никнейм');
//alert('Неправильно введен никнейм');
}else if(data == '1'){
$('#your_message_div').html('Логин свободен!');
//alert('Логин свободен!');
}else if(data == '2'){
$('#your_message_div').html('Логин занят!');
//alert('Логин занят!');
}else{
$('#your_message_div').html('Ошибко:');
}
});
}
$("#test_nick").click(function(){send_data();});
var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();
$("#nick_for_search").keyup(function() {
delay(function(){
send_data();
}, 1000 );
});
});
</script>
<input type="text" id="nick_for_search" name="new_user_name" class="f_input" /> <a href="#" id="test_nick">проверить</a>
<div id="your_message_div"></div>
<?php
break;
case "search":
$aviable_nick_arr = array('test','user','admin');
$nick_for_search = isset($_POST['nick_for_search'])?$_POST['nick_for_search']:'';
//echo $nick_for_search.' --- ';
if ($nick_for_search == ''){
echo 'error';
exit;
}
if (in_array($nick_for_search, $aviable_nick_arr)){
echo '2';
}else{
echo '1';
}
exit;
break;
}
?>