0

次の jquery は、データベースにユーザー名と電子メールがあるかどうかを確認します。false または ture をエコーすると、jquery は機能しますが、PHP エラーが発生します。したがって、PHP コードから false または true を返したいだけです。しかし、私がそれを行うと、jqueryは機能しません。

ここで何が間違っていますか?

前もって感謝します。

Jクエリ

$(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 ステートメントを使用して何かを出力することはできません。echoまたはprint()、戻り値を使用する必要があります。

于 2012-04-11T13:20:15.613 に答える