【问题标题】:my jquery code is not working code igniter我的 jquery 代码不起作用
【发布时间】:2013-01-25 20:08:24
【问题描述】:

这是我的 javascript 代码...我在我的控制器中编写了一个函数,如果返回 false,那么我将回显“userNo”,否则会回显 json ..这是我的 javascript,其中只有 else 部分是如果部分不工作......我也检查了萤火虫..我得到一个响应“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);

    }




}

【问题讨论】:

    标签: php javascript json codeigniter jquery


    【解决方案1】:

    代替echo "userNO",尝试使用它:

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

    ...在你的 JS 中,使用这个:

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

    【讨论】:

    • 如何在 userNo 部分中隐藏 div ....如果我这样做 $('#hide').hide(); ..然后它没有工作..但成功提醒值
    猜你喜欢
    • 1970-01-01
    • 2015-07-22
    • 1970-01-01
    • 1970-01-01
    • 2018-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多