duancan2539 2010-12-16 08:44
浏览 26

无法在Code ignitor1.7.3中处理Ajax请求

Following of my code which is working fine in code ignitor 1.7.1 now not able to invoke controller method user/checkAvailability?requestSource=USER_AVAILABILITY it goves to error block and printing alert as alert('In side Error');

I found that none of Jquery Ajax request not working ..

not able to understand why its not going to call controller method,

Please help

function checkAvailability(){   $.blockUI({message: null}); 
    var newMessage = 'E1';
    $('#searchLoading').show();     alert('I am here');     $.ajax({
                type: "post",
                url: "user/checkAvailability?requestSource=USER_AVAILABILITY",
                cache: false,               
                data: "userName=" + $("#userName").val(),
                success: function(json){
                    alert("Printing Json");
                    try{
                        $.unblockUI();                  
                        var obj = JSON.parse(json);                                         

                        if(obj[0].STATUS=='true'){                                                
                            newMessage = "E15";
                            $('#checkUser').hide();                          
                        }else{
                            newMessage = "E16";                     
                            $("#checkUser").hide();                    
                        }                   
                        showMessage(newMessage);
                        $('#searchLoading').hide();
                    }catch(e) {     
                            alert('In side Exception');
                            showMessage("E1");  
                            $.unblockUI();  
                            $('#searchLoading').hide();
                    }       
                },
                error: function(){

                    alert('In side Error');
                    $('#searchLoading').hide();
                    $.unblockUI();                  
                    $("#checkUser").hide();                     
                    showMessage(newMessage);        
                    $( "form" )[0].reset();

                }        });
          }

CI Method in controller User

/**
        This method is used to check User Name availabiliy.
    */

    public function checkAvailability(){    

        $userName = trim($this->input->post('userName'));

        $query = $this->UserModel->getUser($userName);  

        $status =array("STATUS"=>"true");   

        if($query){
            $status = array("STATUS"=>"false");
        }

        echo json_encode (array($status)) ; 
    }
  • 写回答

4条回答 默认 最新

  • doukuanjing5404 2010-12-16 09:28
    关注

    The error usually appears when the AJAX request doesn't reach the page.

    Change the URL in your AJAX request to an absolute path i.e.

    url: "/user/checkAvailability?requestSource=USER_AVAILABILITY"

    or

    url: "http://site.com/user/checkAvailability?requestSource=USER_AVAILABILITY"

    评论

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错