Home  >  Article  >  Backend Development  >  Methods for judging post, ajax, and get requests in the CI framework

Methods for judging post, ajax, and get requests in the CI framework

不言
不言Original
2018-07-05 14:32:302650browse

This article mainly introduces the method of judging post, ajax, and get requests in the CI framework. It has certain reference value. Now I share it with you. Friends in need can refer to it

CI framework Methods similar to IS_POST, IS_AJAX, and IS_GET in the tp framework are not provided.

We have to make our own wheels. Next, we will introduce how to define these methods for judging requests. Actually, it's really simple.

First open constants.php, which is a file that defines constants. Then add these lines of code to the file.

//定义请求数据的方法
define('IS_POST',strtolower($_SERVER["REQUEST_METHOD"]) == 'post');//判断是否是post方法
define('IS_GET',strtolower($_SERVER["REQUEST_METHOD"]) == 'get');//判断是否是get方法
define('IS_AJAX',isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');//判断是否是ajax请求

Then, you can call these methods in the controller file.

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

How to view logs in laravel in the terminal

Introduction to nginx memcache cache

The above is the detailed content of Methods for judging post, ajax, and get requests in the CI framework. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn