简体   繁体   English

我的jQuery代码无法正常工作的代码点火器

[英]my jquery code is not working code igniter

this is my javascript code ...i have written a function in my controller in which if false is return then i am echoing the 'userNo' other wise echo the json .. here is my javascript in which only else part is working not if part ... i have checked in firebug also .. i am getting a response "userNo" but dont know why it is not running the first part 这是我的javascript代码...我已经在控制器中编写了一个函数,如果返回false,那么我在回显'userNo';否则,在json中回显json ..这是我的javascript,其中只有其他部分在起作用部分...我也检查了萤火虫..我收到响应“ 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>

my Controller 我的控制器

    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);

    }




}

Instead of echo "userNO" , try to use it: 代替使用echo“ userNO” ,请尝试使用它:

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

... and in your JS, use this: ...并在您的JS中使用:

if (response.return == "userNo") { // ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM