How do I check if the request is made via AJAX in CodeIgniter?

前端 未结 7 2069
余生分开走
余生分开走 2020-11-28 08:29

How do I check if the request is an AJAX? I am using CodeIgniter. I have a link that when it clicked, it\'ll open the pop-up dialog window this is done through ajax it reque

7条回答
  •  情话喂你
    2020-11-28 09:03

    Codeigniter has inbuilt function to check if the request is made using Ajax call.

    You can use the following way to validate if a controller/segment is called using Ajax or not.

    input->is_ajax_request()){
           show_404();
         }
    
      }
    
    }
    

    You can use many other checks as well using input class. Few of them are

    • $this->input->get_request_header();
    • $this->input->is_cli_request()
    • $this->input->ip_address()

    You can view complete list of available methods at Official documentation

提交回复
热议问题