以下jquery是检查数据库中是否有用户名和电子邮件。当我回显 false 或 ture 时,jquery 可以工作,但它会给出 PHP 错误。所以我只想从 PHP 代码中返回 false 或 true。但是当我这样做时,jquery 不起作用。
我在这里做错了什么?
提前致谢。
jQuery
$(document).ready(function(){
$("#name").blur(function()
{
var nameval = $(this).val();
if(nameval)
{
...
...
//check the username exists or not from ajax
$.post("<?php echo site_url('welcome/user_availability'); ?>",{ what:$(this).val(), where:"name" } ,function(data)
{
if(data==false) //if username not avaiable
{
$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
{
//add message and change the class of the box and start fading
$(this).html('This User name Already exists').addClass('messageboxerror').fadeTo(900,1);
});
}
else
{
$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
{
//add message and change the class of the box and start fading
$(this).html('Username available to register').addClass('messageboxok').fadeTo(900,1);
});
}
});
}
else
{
$("#msgbox").fadeTo(200,0);
}
});
...
...
PHP
function user_availability()
{
$module = "subscribers";
$where = $this->input->post('where');
$what = $this->input->post('what');
$customers = $this->MKaimonokago->getAllSimple($module, $where , $what );
if (!empty($customers))
{
//user name is not available
return false; // I want to use return here.
// this works but it gives php error
// echo "false";
}
else
{
return true;
}
}
PHP 错误
ERROR - 2012-04-11 21:43:06 --> Severity: Warning --> Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/kaimonokago2.0/application/modules/welcome/controllers/welcome.php:1084) /Applications/MAMP/htdocs/kaimonokago2.0/system/core/Output.php 391