本文实例讲述了 ThinkPHP 中使用 ajax 的方法, 提交表单如下图所示:
点击提交, 不需要刷新本页, 将内容提交到数据库当中, 并在本页显示提交的内容如下图所示:
一 jquery 实现方法:
MessageAction.class.php 页面代码如下:
- <?php
- class MessageAction extends Action{
- function index(){
- $this->display();
- }
- function add(){
- //ajaxReturn(数据,'提示信息', 状态)
- $m=M('message');
- if($m->add($_GET)){
- $this->ajaxReturn($_GET,'添加信息成功',1);
- }else{
- $this->ajaxReturn(0,'添加信息失败',0);
- }
- }
- }
- ?>
来源: https://www.php1.cn/detail/php-0e36176629.html