- 浏览: 13635424 次
- 性别:
- 来自: 洛杉矶
文章分类
- 全部博客 (1994)
- Php / Pear / Mysql / Node.js (378)
- Javascript /Jquery / Bootstrap / Web (435)
- Phone / IOS / Objective-C / Swift (137)
- Ubuntu / Mac / Github / Aptana / Nginx / Shell / Linux (335)
- Perl / Koha / Ruby / Markdown (8)
- Java / Jsp (12)
- Python 2 / Wxpython (25)
- Codeigniter / CakePHP (32)
- Div / Css / XML / HTML5 (179)
- WP / Joomla! / Magento / Shopify / Drupal / Moodle / Zimbra (275)
- Apache / VPN / Software (31)
- AS3.0/2.0 / Flex / Flash (45)
- Smarty (6)
- SEO (24)
- Google / Facebook / Pinterest / SNS (80)
- Tools (22)
最新评论
-
1455975567:
xuezhongyu01 写道wocan23 写道我想问下那个 ...
Mysql: LBS实现查找附近的人 (两经纬度之间的距离) -
xuezhongyu01:
wocan23 写道我想问下那个111.1是怎么得来的我也看不 ...
Mysql: LBS实现查找附近的人 (两经纬度之间的距离) -
18335864773:
试试 pageoffice 在线打开 PDF 文件吧. pag ...
jquery在线预览PDF文件,打开PDF文件 -
青春依旧:
opacity: 0.5; 个人喜欢这种方式!关于其他css特 ...
css透明度的设置 (兼容所有浏览器) -
July01:
推荐用StratoIO打印控件,浏览器和系统的兼容性都很好,而 ...
搞定网页打印自动分页问题
(E文,没时间翻译)
首先做一个Ajax的helper,下面是说明,很简单,粘贴复制就可以了。。。
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); function is_ajax() { return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'; } ?>
Copy the following code into a file. Save the file as ajax_helper.php and save in your application/helpers/ folder.
Load it if you need if by:
Normal loading
This is pretty much how we normally include helpers. This is the best approach unless you would use the ajax helper most of the time.
$this->load->helper('ajax');
Autoloading
Open your config.php file located at application/config/ . Look for this line.
$autoload['helper'] = array();
Add yours to the list
$autoload['helper'] = array('ajax');
You should not add _helper when adding it to the autoload['helper'] array.
下面是详细说明: 初中英语够你看懂以下内容了 (最后一行还有测试页面呢~~)
AJAX can be seen almost everywhere on the web. Yahoo uses it. Google uses it. My boss uses it. My grandmother uses it — well maybe not but that shouldn't stop you from using it.
Here's an awesome tutorial to use AJAX with CodeIgniter.
This tutorial assumes that you have a form set-up like so:
<?php echo form_open(current_url(), array('id' => 'registration_form'));?> <label for="username">Username: </label> <input type="text" class="span-2" value="" name="username" id="username" /><br /> <label for="first_name">First Name: </label> <input type="text" value="" name="first_name" id="first_name" /><br /> <label for="last_name">Last Name: </label> <input type="text" value="" name="last_name" id="last_name" /><br /> <label for="desc">Password: </label> <input type="password" value="" name="password" id="password" /><br /> <label for="desc">Repeat Password: </label> <input type="password" value="" name="passconf" id="passconf" /><br /> <label for="desc">Email: </label> <input type="text" value="" name="email" id="email" /><br /> <label for="register"> </label> <input type="submit" value="Register" name="register" id="register" class="update" /> </form>
The form starts with the usual form helper , form_open(). The rest is pretty much normal.
Now with the Javascript. In this tutorial, we will use jQuery
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
Now we do AJAX
Javascript
<script type="text/javascript"> $(document).ready(function() { $('#registration_form').submit(function(){ $.post("<?php echo site_url(current_url());?>", { username: $('#username').val(), first_name: $('#first_name').val(), last_name: $('#last_name').val(), password: $('#password').val(), passconf: $('#passconf').val(), email: $('#email').val(), }, function(data){ alert(data); } ); return false; }); }); </script>
Explanation
$.post("<?php echo site_url(current_url());?>", {
The fourth line of the previous code will request to the current url. This means that if you are on '/this/page/', it will request to '/this/page/'.
username: $('#username').val(), first_name: $('#first_name').val(), last_name: $('#last_name').val(), password: $('#password').val(), passconf: $('#passconf').val(), email: $('#email').val()
The above will be the information we will post. For example, username: $('#username').val()
will pass the value
of the element with the id, username. In our case, that would be one of the inputs.
function(data){ alert(data); }
The above is the callback. From here we accept the response from our request. In our case, we alert the response.
CodeIgniter
function ajax_with_codeigniter() { $this->load->library('form_validation'); $this->load->helper(array('ajax', 'form')); $this->form_validation->set_rules('username', 'Username', 'callback_username_check'); $this->form_validation->set_rules('first_name', 'First Name', 'required'); $this->form_validation->set_rules('last_name', 'Last Name', 'required'); $this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]'); $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required'); $this->form_validation->set_rules('email', 'Email', 'required|valid_email'); if ($_POST) { if (is_ajax() AND $this->form_validation->run() === TRUE) { echo "Registration Successful"; } else { echo validation_errors(' ',' '); } } else { $this->load->view('code/ajax_with_codeigniter/ajax_with_codeigniter'); } }
Explanation
$this->load->library('form_validation'); $this->load->helper(array('ajax','form'));
The above code will load the library ajax helper, the form helper and the form validation library.
$this->form_validation->set_rules('username', 'Username', 'callback_username_check'); $this->form_validation->set_rules('first_name', 'First Name', 'required'); $this->form_validation->set_rules('last_name', 'Last Name', 'required'); $this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]'); $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required'); $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
The above code is how we set rules. Pretty normal if you have used CodeIgniter in the past.
if ($_POST) { if (is_ajax() AND $this->form_validation->run() === TRUE) { echo "Registration Successful"; } else { echo validation_errors(' ', ' '); } } else { $this->load->view('code/ajax_with_codeigniter/ajax_with_codeigniter'); }
The last piece of code checks for anything POST ed. Remember that we are requesting to the same method so we should check for anything POST ed before we output anything. This conditional statement is only used because of the situation. You normally won't have this checkpoint.
There's something POST ed
When we know that there was something POST ed, we check if the request was done via the ajax_helper. This is just some check if we only want AJAX requests. The second part of the condition is if the data passed passes the validation rules we set up. If it checks out fine, we send our message, "Registration successful". If not, we send the errors.
Nothing was POST ed
When we know that nothing was POST ed, we load the view. This pretty much activates when we just loaded the page.
Demo
You can visit our AJAX with CodeIgniter demo .
发表评论
-
CakePHP你必须知道的21条技巧
2012-10-19 06:25 1847原文链接:http://www.avatarfinancial ... -
cakephp 1.3 Views
2012-10-09 06:12 1406Section 1 Views 视图 一个vie ... -
cakephp 1.3 Models
2012-10-09 06:07 2469Section 1 What is a model? ... -
cakephp 1.3 Controller
2012-10-09 05:49 3298Controller 一个controller用于管理 ... -
cakephp 1.3 配置CakePHP
2012-10-09 05:31 4600Section 1 数据库配置 app/config/ ... -
CakePHP 2.x十分钟博客教程
2012-10-07 01:27 243651. CakePHP2十分钟博客教 ... -
Create an Admin panel with CodeIgniter
2010-05-23 02:15 4138Create an Admin panel with Code ... -
Codeigniter Grid 使用方法 (flexigrid)
2010-05-23 02:05 2761来源:http://codeigniter.com/forum ... -
CI集成 ckeditor 配置
2010-05-23 01:34 3720配置 ckeditor 1.上传 下载 ckedito ... -
codeigniter 辅助函数 - 敏感词过滤
2010-05-05 06:18 4541我们都知道有些敏感的词汇是不适合出现在互联网上的,特别是在有用 ... -
实现简单 codeigniter 缓存 (cache)
2010-04-30 23:47 5233代码 class Test extends Contr ... -
CKEditor Helper for CodeIgniter
2010-04-19 00:37 3940Using CKEditor as a plugin in y ... -
codeigniter 生成 excel
2010-04-19 00:33 3287Excel Plugin Th ... -
CakePHP 中文手册
2010-04-14 21:04 2309基本概念 Section1 简介 ... -
利用 Cache_Lite代替codeigniter中的cache功能
2010-01-29 06:15 5470codeigniter的功能纵然强大,也有不足之处。其cach ... -
CodeIgniter 操作PDF ( Generating PDF files using CodeIgniter )
2010-01-03 04:03 3568PDF files rock! Some of the p ... -
CodeIgniter 合作 Authorize.net
2009-12-30 00:25 1556function payment(){ // 略... ... -
CodeIgniter 合作paypal
2009-12-30 00:15 2315<?php class Paypal extend ... -
CodeIgniter 操作 CSV
2009-12-29 07:17 4580A Comma separated values (CSV) ... -
codeigniter 操作 Rss
2009-12-29 07:12 1926I wrote a codeigniter library t ...
相关推荐
php +CodeIgniter + jquery + 组件开发的二手车交易系统=>毕设.zip
CodeIgniter + Smarty集成 集成验证码 Code Igniter是一个很不错的PHP框架,Smarty是一个非常好的显示层框架,将这两个框架集成安装到一起.
vue + vue-router +axios + element UI + PHP + CodeIgniter + Mysql 项目管理系统. 软件开发设计:应用软件开发、系统软件开发、移动应用开发、网站开发Node.js、C++、Java、python、web、C#等语言的项目开发与学习...
Codeigniter 入门项目 NodeJS 入门项目 令人惊叹的仪表板页面布局 使用 Bootstrap 4 构建 干净的代码 基于组件的结构 悬停效果 谷歌地图 易于定制 独特、干净和现代的设计 完全响应 跨浏览器优化 使用免费的 Google ...
CI是一套给 PHP 网站开发者使用的应用程序开发...它提供一套丰富的标准库以及简单的接口和逻辑结构,其目的是使开发人员更快速地进行项目开发。使用CI可以减少代码的编写量,并将你的精力投入到项目的创造性开发上。
CodeIgniter+架构的说明教程.pdf CodeIgniter用户指南(版本1.7.2).chm CodeIgniter资料+ci+jquery范例.zip PHP 敏捷开发框架CodeIgniter.chm Wrox,.Professional.CodeIgniter.(2008).BBL.[0470282452].pdf
Ajax-Codeigniter-3-Ajax-Form-Submission.zip,“codeigniter 3 ajax表单提交和验证教程”一集的源代码,ajax代表异步javascript和xml。它是多种web技术的集合,包括html、css、json、xml和javascript。它用于创建...
CodeIgniter and Ajax using jQuery.zip
【项目资源】: 包含前端、后端、移动开发、操作系统、人工智能、物联网、信息化管理、数据库、硬件开发、大数据、课程资源、音视频、网站开发等各种技术项目的源码。 ... 【项目质量】: 所有源码都经过严格测试,...
Ajax-CodeIgniter-Ajax-Search.zip,codeigniter ajax实时搜索,ajax代表异步javascript和xml。它是多种web技术的集合,包括html、css、json、xml和javascript。它用于创建动态网页,其中网页的小部分在不重新加载网页...
Ajax-codeigniter-ajax-crud.zip,使用codeigniter、jquery和ajax实现简单的crud,ajax代表异步javascript和xml。它是多种web技术的集合,包括html、css、json、xml和javascript。它用于创建动态网页,其中网页的小...
attendance codeigniter+angularjs+Bootstrap 写的学生考勤系统 数据库 MySQL
只是一个基本示例,说明如何将CodeIgniter 3 + Vue.js 3 + Vite与支持的热模块替换(HMR)集成。 CodeIgniter 3 + Vue.js 3 + Vite这只是一个基本示例,说明如何将CodeIgniter 3 + Vue.js 3 + Vite与受支持的热模块...
CodeIgniter-PhpStorm CodeIgniter 2.2.1 支持 PhpStorm 8.0 如何 创建新项目时,克隆此存储库而不是 CodeIgniter 上的默认存储库。 使用 PhpStorm 打开文件夹。 仅将以下文件标记为纯文本: '系统/核心/...
“#codeigniter-vue”
XCRUD + Codeigniter +管理引导程序#引导程序#glyphicons #xcrud #codeigniter #trik #tips 管理员登录电子邮件: 密码:entol123 用户登录: 电子邮件: 密码:11111111 原始Google+发布 原始源代码:源代码: :
CodeIgniter-Ratchet-WebsocketNOTICE : This project is NOT production ready. 该库包含使用CodeIgniter-Ratchet-Websocket和AngularJS作为客户端javascript框架实时注释/发布的示例。 我没有做任何火箭科学来实现...
可以使用它来读取、写入不同格式的电子表格。而Codeigniter是一个功能强大的PHP框架。...2.安装PHPExcel到Codeigniter1)解压压缩包里的Classes文件夹中的内容到application\libraries\目录下,目录结构如下:–applica