首页 > PHP资讯 > HTML5培训技术 > jQueryAjax与后台交互封装js应用

jQueryAjax与后台交互封装js应用

HTML5培训技术
//公共js pagging.jsvar currentPage=1;var maxpagesize;var message;var url = "";var param = "";//加一个回调函数--修改,删除通用ajax请求function saveData(param,url,message,addDtaFun,tb){	if (confirm(message)) {		$.ajax({			url : url,			type : "post",			data : param,//记住,data为传送的参数 			dataType : "json",			error : function(XMLHttpRequest, textStatus, errorThrown) {				//alert("========" + XMLHttpRequest.redayState + "|" + textStatus + "|" + errorThrown);			},			success : function(data) {				if (data == 1) {					alert("操作成功!");										tb.html("");					addDtaFun();									} else {					alert("操作失败");				}							}		})			}	}//查询所有部门数据function addDept(deptId,url) {	var param = "";	$.ajax({		url : url,		type : "post",		data : param,//记住,data为传送的参数 		dataType : "json",		beforeSend : function() {		},		error : function(XMLHttpRequest, textStatus, errorThrown) {			//alert("========" + XMLHttpRequest.redayState + "|" + textStatus+ "|" + errorThrown);		},		success : function(data) {			$.each(data, function(i, d) {				//jquery取val()取不到就取text的值  select				var $option = $("");				$option.attr("value", d.c_dep_name);				$option.text(d.c_dep_name);				deptId.append($option);			})		}	})}//根据部门进行联动function addPerson(person, param) {	var url = contextPath + "/emp/empList.action";	$.ajax({		url : url,		type : "post",		data : param,//记住,data为传送的参数 		dataType : "json",		beforeSend : function() {		},		error : function(XMLHttpRequest, textStatus, errorThrown) {			alert("========" + XMLHttpRequest.redayState + "|" + textStatus					+ "|" + errorThrown);		},		success : function(data) {			$.each(data, function(i, d) {				var $option = $("");				$option.text(d.c_emp_name);				person.append($option);			})		}	})}//查询安环部所有员工:function addcheckPersons(id) {	var url = contextPath + "/emp/empCheckPerson.action";	$.ajax({		url : url,		type : "post",		//data : param,//记住,data为传送的参数 		dataType : "json",		beforeSend : function() {		},		error : function(XMLHttpRequest, textStatus, errorThrown) {			alert("========" + XMLHttpRequest.redayState + "|" + textStatus					+ "|" + errorThrown);		},		success : function(data) {			//alert("data==="+data);			$.each(data, function(i, d) {				var $option = $("");				$option.text(d.c_emp_name);				id.append($option);			})		}	})}//分页function pagingFunc(tb,addDtaFun) {			tb.html("");//清空内容	 		addDtaFun();}//跳转function goPage() {	var page=$("#page").val();	//页数合法进行分页		if (valPagesize(page, maxpagesize) == true) {		paging(page);	}}//判断是否合法页数function valPagesize(size,maxpagesize) {	if (size >= 1 && size <= maxpagesize) {		return true;	} else if (size < 1) {		alert("页不能小于1");		$("#page").focus();		return false;	} else if (size > maxpagesize) {		alert("输入的页数不能大于最大页数");		$("#page").focus();		return false;	} else {		alert("输入的页数不合法");		$("#page").focus();		return false;	}}


引用文件include.inc<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%><%    //上下文路径    String contextPath=request.getContextPath();    //主题路径    String themePath="/template/themes/default";    pageContext.setAttribute("themePath",themePath);    pageContext.setAttribute("contextPath",contextPath);%>
<script type="text/javascript" src="${contextPath}${themePath}/js/jquery-1.4.2.js">《script》
<script type="text/javascript" src="${contextPath}${themePath}/js/checkidcard.js">《script》
<script type="text/javascript" src="${contextPath}${themePath}/js/page.js">《script》<script type="text/javascript" src="${contextPath}/plugs/My97DatePicker/WdatePicker.js">《script》<script type="text/javascript" src="${contextPath}/plugs/FusionCharts/JSClass/FusionCharts.js">《script》
<script type="text/javascript" src="themes/default/js/jquery.tablesorter.js">《script》《script》    var themePath="<%=themePath%>";    var contextPath="<%=contextPath%>";《script》添加页面jsp:punish_add.jsp<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>            <%@ include file="/template/main.inc"%>            
; charset=UTF-8" pageEncoding="UTF-8"%><%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%><%@ include file="/template/include.inc"%>
《script》function showMenuInfo(obj){ alert(obj.text()) $("#menuInfo").text(obj.text());}《script》

left.jsp,safe_top.jsp及后台代码略

项目截图:



本文由欣才IT学院整理发布,未经许可,禁止转载。