PHP头条
热点:

ThinkPHP中ajax使用实例教程


ThinkPHP

本文实例讲述了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);  
    }
  }
 
}
?>

模板index.html代码如下:



相关文章

PHP之友评论

今天推荐