Hi everybody, I getting a problem to check username availability checking using jquery.
this is my form page…
<?php
Yii::app()->clientScript->registerCoreScript('jquery');
Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl.'/js/ajaxreq.js');
?>
<div class="form">
<?php $form=$this->beginWidget(‘CActiveForm’, array(
'id'=>'mst-thana-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<p class="note">&nbsp;<span id="msgbox" style="display:none"></span></p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'name'); ?>
<?php echo $form->textField($model,'name',array('size'=>50,'maxlength'=>50,'id'=>'name', 'link'=>Yii::app()->request->baseUrl.'/protected/availability.php', 'onKeyup'=>'isDoubleByte(event,this.id)')); ?>
<?php echo $form->error($model,'name'); ?>
</div>
<div class="row buttons" style="display:none" id="butt">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
This is my ajaxreq.js file…
$(document).ready(function()
{
$("#name").blur(function()
{
$("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
$.post("protected/availability.php",{ user_name:$(this).val()} ,function(data)
{
if(data=='no') //if username not avaiable
{
$("#msgbox").fadeTo(200,0.1,function()
{
$(this).html('This name Already exists').addClass('messageboxerror').fadeTo(900,1);
});
}
else
{
$("#msgbox").fadeTo(200,0.1,function()
{
$(this).html('name available to create').addClass('messageboxok').fadeTo(900,1);
});
$('#butt').show();
}
});
});
});
and this is availability.php file…
<?php
$rowId = 0;
$user_name=$_POST[‘user_name’];
$district=$_POST[‘district’];
$fa = MstUser::model()->findAllByAttributes(array(‘name’=>$user_name));
$ld=CHtml::listData($fa,'userId','userId');
foreach($ld as $i){
$rowId = $i;
}
if ($rowId!=0)
{
echo $rowId;
}
else
{
echo $rowId;
}
?>
when I check user availability it still showing "checking…"
please any one help me.