2

i am using codeigniter. I have set a form validation via jquery and after validation the data /control is not moving on to the Controller. Here is my jquery code

var data1 = {               
                username:$("#username").val(),
                password:$("#password").val()           
                }


            $.ajax({

                    type:'POST',
                    url:base_url+"site/chk_info",


                    data:data1,

                    success: function (response){

                            alert (response);

                        },

                    error:function (){
alert ("Sorry we are getting problems plz try again latter");

                        }

                    });  // end ajax

Here is my controller method.

public function chk_info(){

        return true;    

    }

The problem is in jquery the controll in not entering into the success function it always getting into the error function.

MonkeyZeus
  • 20,375
  • 4
  • 36
  • 77
Abbasi
  • 588
  • 1
  • 7
  • 26

2 Answers2

0

chk_info() is only returning true IF PHP was listening and acting upon it.

You should be echo-ing true like this instead:

public function chk_info(){
    echo 'true';
}
MonkeyZeus
  • 20,375
  • 4
  • 36
  • 77
0

try this i think its url problem

 $.ajax({

        type:'POST',
        url:'<?php echo base_url() ?>site/chk_info',
        data:data1,
         success: function (response){
                  alert (response);
                     },

                    error:function (){
alert ("Sorry we are getting problems plz try again latter");

                        }

                    });
Dexter
  • 1,804
  • 4
  • 24
  • 53