本文实例为大家分享了ajax和PHP实现简单的流程管理,供大家参考,具体内容如下
首先要先有一个新建流程的页面xinjian.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>新建</title><script src="../FENGZHUANG/jquery-3.1.1.min.js"></script></head><body><h1>新建流程</h1><div>请选择节点人员:<select id="user"> <?php session_start();//需要将一些数据暂时存在session里 include("../FENGZHUANG/DBDA.class.php"); $db = new DBDA(); $sql = "select * from users"; $arr = $db->Query($sql); foreach($arr as $v) { echo "<option value='{$v[0]}'>{$v[2]}</option>"; } ?></select><input type="button" value="添加节点" id="add" /></div><br /><div> <?php if(!empty($_SESSION["user"])) { $attr = $_SESSION["user"]; foreach($attr as $k=>$v) //索引为$k,取值为$v { $sname = "select name from users where uid='{$v}'"; //取出名称 $name = $db->StrQuery($sname); echo "<div>{$k}--{$name}--<input type='button' value='删除' key='{$k}' class='del' /></div>"; //向处理页面传的是key的值 } } ?></div><br /><div>请输入流程名称:<input type="text" id="name" /></div><br /><input type="button" value="保存" id="btn" /></body><script type="text/javascript">//添加节点按钮加点击$("#add").click(function(){ var uid = $("#user").val(); $.ajax({ url:"chuli.php", data:{uid:uid,type:0}, //传入一个type参数,以确保在同一页面处理时与其它的分开处理 type:"POST", dataType:"TEXT", success: function(data){ window.location.href="xinjian.php" rel="external nofollow" rel="external nofollow" ; //刷新页面 } }); }) //给删除按钮加点击$(".del").click(function(){ var key = $(this).attr("key"); //取删除的是哪条数据 $.ajax({ url:"chuli.php", data:{key:key,type:1}, type:"POST", dataType:"TEXT", success:function(data){ window.location.href="xinjian.php" rel="external nofollow" rel="external nofollow" ; } }); })//给保存按钮加点击$("#btn").click(function(){ var name = $("#name").val(); //取输入框中输入内容的值 $.ajax({ url:"chuli.php", data:{name:name,type:2}, type:"POST", dataType:"TEXT", success:function(data){ alert("保存成功!"); } }); })</script></html>
数据库图片:
新闻热点
疑难解答