codeigniter failed when use is_ajax_request function on ajax request

Tags: , , , ,

I’m trying to update user password from panel admin with ajax request is use is_ajax_request() on the controller but this function says I’m not in ajax request. why does this happen?

Here’s my ajax jquery:

    url: urlTarget,
    traditional: true,
    type: 'post',
    dataType: 'json',
    data: {currentPassword:currentPassword, newPassword:newPassword},
    success: function ( result ) {
        if( result.status == 'success' ){
            window.location = baseUrl;
            $("#login-submit").attr("disabled", false);
    error: ajax_error_handling

on the controller:

    private function ajax_checking(){
        if ( !$this->input->is_ajax_request() ) {
            redirect( base_url() );

    public function change_password(){

        $postData = $this->input->post();
        $id = $this->session->userdata('id_admin');

        if($this->admin_model->check_current_password($id, $postData['currentPassword'])){
            $this->admin_model->change_password($id, $postData['newPassword']);
            $send["status"] == "success";
            $send["status"] == "fail";

        echo json_encode($send);

since the result of ajax_checking is false the system redirect me to the set url. Anyone can help me?


thanks for your help smit, here’s the problem that redirect me to baseUrl :

i set this on the controller, it happens because i have this script on the controllers that redirect me to the basicUrl:

    public function __Construct() {
        if($this->session->userdata('logged_in') ) {
            redirect( base_url() );

Source: stackoverflow