0

以下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
4

2 回答 2

1

您描述的错误与 HTTP 标头有关。当您尝试调用header()session_start()setcookie()在第一个 echo 语句之后,通常会出现错误。请注意,<?php标记前的空行也会打印换行符。

你不能用 return 语句打印一些东西,在你应该有一个echoprint()返回值的地方。

于 2012-04-11T13:20:15.613 回答
1

尝试:

// in php
echo(json_encode(TRUE));
于 2012-04-11T13:08:37.630 回答