那么问题来了。我前台取input里面的值传不到后台php控制器里啊。求拯救啊~~
dump($where)是空数组
介块是ajax的
<script type="text/javascript">
$(function () {
var arr=$('#registerForm').serializeArray();
$.param(arr);
$("#username").bind("blur", function () {
$.ajax({
url:"<{:U('reg/cfname')}>",
data:user=arr,
type:"post",
dataType: 'json',
success: function (data) {
if(data==1){
alert ("用户名不可用")
}else{alert ("用户名可用")}
}
});
})
});
</script>
介块是php的
public function cfname(){
$user=M('Cpy');
$where['name']=I('post.name');
dump($where);
exit;
$list=$user->where($where)->find();
if(!$list){
$data=M('Ywy');
$list1=$data->where($where)->find();
if(!$list1){
$data=0;
return $data;
}
else{
$data=1;
return $data;
}
}
else{
$data=1;
return $data;
}
}
介块是表单
<form name="registerForm" id="registerForm" method="post" onsubmit="onQuermm()" >
<input type="text" name="name[ ]" id="username" maxlength="16" class="input_txt" placeholder="用户名">
</form>
dump($where)是空数组
介块是ajax的
<script type="text/javascript">
$(function () {
var arr=$('#registerForm').serializeArray();
$.param(arr);
$("#username").bind("blur", function () {
$.ajax({
url:"<{:U('reg/cfname')}>",
data:user=arr,
type:"post",
dataType: 'json',
success: function (data) {
if(data==1){
alert ("用户名不可用")
}else{alert ("用户名可用")}
}
});
})
});
</script>
介块是php的
public function cfname(){
$user=M('Cpy');
$where['name']=I('post.name');
dump($where);
exit;
$list=$user->where($where)->find();
if(!$list){
$data=M('Ywy');
$list1=$data->where($where)->find();
if(!$list1){
$data=0;
return $data;
}
else{
$data=1;
return $data;
}
}
else{
$data=1;
return $data;
}
}
介块是表单
<form name="registerForm" id="registerForm" method="post" onsubmit="onQuermm()" >
<input type="text" name="name[ ]" id="username" maxlength="16" class="input_txt" placeholder="用户名">
</form>
于是 arr 永远是一个空数据(只有默认值)的数据体,不能反映表单里的数据变化