ci检测是ajax还是页面post提交数据的方法,ciajax
本文实例讲述了ci检测是ajax还是页面post提交数据的方法。分享给大家供大家参考。具体实现方法如下:
一、问题:
因为项目需要我们希望知道提交数据来源是由ajax提交过来的数据还是由页面的post提交过来的数据从而进行不同层面上的处理。
二、解决方法:
在php中解决方法如下:
如果是ajax请求,以下表达式的值为真
复制代码 代码如下:
$_SERVER["HTTP_X_REQUESTED_WITH"]=="XMLHttpRequest"
就是一个PHP的环境变量。
ci中处理办法:
复制代码 代码如下:
define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
define("IS_POST", strtolower($_SERVER['REQUEST_METHOD']) == 'post');
记得在用THINKPHP的时候有内置两个常量 IS_AJAX 与 IS_POST,想在ci中使用查了半天好像没有找到,那就自动动手丰衣足食
在项目的config/constants.php 配置文件加上上边两行代码,这下你就可以在所有的方法中直接调用
例如:
复制代码 代码如下:
if(IS_POST){
...
}
if(IS_AJAX){
...
}
希望本文所述对大家的CI框架程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

Atom editor mac version download
The most popular open source editor

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software