0

これは私のJavaScriptコードです...私はコントローラーに関数を書きました.falseが返された場合、「userNo」をエコーし​​、そうでない場合はjsonをエコーし​​ます..これは、else部分のみが機能する私のjavascriptです一部...私はfirebugもチェックインしました..「userNo」という応答を受け取りましたが、最初の部分を実行していない理由がわかりません

    <script type="text/javascript">


    $(document).ready(function(){
         $('#hide').hide();
        $('#bill_no').blur(function(){

            if( $('#bill_no').val().length >= 3 )
                {
                  var bill_no = $('#bill_no').val();
                  getResult(bill_no); 
                }
            return false;
        })
        function getResult(billno){
            var baseurl = $('.hiddenUrl').val();
           $('.check').addClass('preloader');
            $.ajax({
                url : baseurl + 'returnFromCustomer_Controller/checkBillNo/' + billno,
                cache : false,
                dataType: 'json',
                success : function(response){
                     $('.check').removeClass('preloader');

                    if (response == "userNo") //this part is not working
                        alert("true");
                    else
                    $('.check').removeClass('userNo').addClass('userOk');
                    // $(".text").html(response.result);
                     $('#hide').show();
                     $(".text1").html(response.result1);
                     $(".text2").html(response.result2);
                     $(".text3").html(response.result3);

                }
            })
        }
    })


  </script>

私のコントローラー

    function checkBillNo($billno)
{
    $this->load->model('returnModel');

    $query = $this->returnModel->checkBillNo($billno);

    //$billno =   $this->uri->segment(3);
    $billno_results  = $this->returnModel->sale($billno);

    if (!$billno_results){

            echo "userNo";


    }else{
        echo json_encode($billno_results);

    }




}
4

1 に答える 1

0

echo "userNO"の代わりに、それを使用してみてください:

echo json_encode(array('return' => 'userNo'));

...そしてあなたのJSでは、これを使用してください:

if (response.return == "userNo") { // ...
于 2013-01-25T20:16:35.970 に答える