jQuery Ajax与后台交互封装js应用

  • 内容
  • 评论
  • 相关
u=864383365,2725830277&fm=21&gp=0.jpg
//公共js pagging.js  
var 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></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></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></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);  
%>  
<!-- 通用变量 -->  
<link rel="stylesheet" href="${contextPath}${themePath}/css/layout.css" type="text/css"></link>  
<link rel="stylesheet" href="${contextPath}${themePath}/css/zfba.css" type="text/css"></link>  
<link rel="stylesheet" href="${contextPath}${themePath}/css/win.css" type="text/css"></link>  
<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>  
<!-- loading  -->  
<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"%>  
<html>  
    <head>  
        <%@ include file="/template/main.inc"%>  
    </head>  
    <body>  
    <div style="width: 100%">  
    <div style="height: 10px"></div>  
    <div class="" style="padding: 3px;">  
    <table width="100%" border="0" cellspacing="0" cellpadding="0">  
      <tr>  
        <td width="18"><img src="${contextPath}${themePath}/images/win_01.gif" width="18" height="42" /></td>  
        <td class="win_box_a"><a href="javascript:closeAddDiv();"><img src="${contextPath}${themePath}/images/win_close.jpg" width="16" height="16" style="float:right;" /></a>更新整改反馈结果:</td>  
        <td width="18"><img src="${contextPath}${themePath}/images/win_03.gif" width="18" height="42" /></td>  
      </tr>  
      <tr>  
        <td class="win_box_b"> </td>  
        <td style="background-color: #fff;">  
            <form name="addForm" id="addForm">  
                <table cellpadding="0" cellspacing="0" class="ldsy_tablist">  
                    <tr>  
                        <td>  
                            姓名:  
                        </td>  
                        <td>  
                            <input type="text"   name="punish.name"  id="name" class="tdInput"/>  
                        </td>  
                        <td>  
                            违章地点:  
                        </td>  
                        <td>  
                            <input type="text"  class="tdInput" name="punish.place" id="place" />  
                        </td>  
                    </tr>  
                    <tr>  
                        <td>  
                            单位:  
                        </td>  
                        <td>  
                            <select name="punish.dept" id="dept_add" class="tdInput">  
                                <option value="">请选择单位:</option>  
                            </select>  
                               
                        </td>  
                        <td>  
                            领导:  
                        </td>  
                        <td>  
                            <select name="punish.leader" id="leader"  class="tdInput">  
                                <option value="">请选择领导:</option>  
                            </select>  
                        </td>  
                    </tr>  
                    <tr>  
                        <td>  
                            处罚原因:  
                        </td>  
                        <td>  
                            <textarea style="width: 100%; height: 60px" id="cause" name="punish.cause" class="tdInput"></textarea>  
                        </td>  
                        <td>  
                            安全条律  
                        </td>  
                        <td>  
                            <select name="punish.rules_id" class="tdInput" id="rules_id" class="tdInput">  
                                <option value="">请选择安全条律</option>  
                                <option value="1">第一条</option>  
                                <option value="2">第二条</option>  
                                <option value="3">第三条</option>  
                            </select>  
                        </td>  
                    </tr>  
  
                    <tr>  
                        <td>  
                            惩罚:  
                        </td>  
                        <td>  
                            <select name="select" class="tdInput" class="tdInput" name="punish.punish_type" id="punish_type">  
                                <option value="">  
                                    请选择处罚方式  
                                </option>  
                                <option  value="1">  
                                    罚款  
                                </option>  
                                <option  value="2">  
                                    培训  
                                </option>  
                            </select>  
                        </td>  
                        <td>  
                            <div id="chengfai">罚款金额:</div>  
                        </td>  
                        <td>  
                            <input type="text"  class="tdInput"  name="punish.punish_money" id="punish_money" />  
                            <input type="text" style="DISPLAY: none" id="traintime"  name="punish.traintime" onfocus="WdatePicker({minDate:'%y-%M-{%d+1}',readOnly:true})" class="tdInput" />  
                        </td>  
                    </tr>      
              
                    <tr >  
                        <td colspan="4" style="text-align:center">  
                            <input type="button" class="btn_w70" value="保存" onclick="addSave()"/>  
                                
                            <input type="reset" value="重置 " class="btn_w70" />  
                                
                        </td>  
                    </tr>  
                </table>  
            </form>  
            </td>  
            <td class="win_box_c"> </td>  
          </tr>  
          <tr>  
            <td valign="top"><img src="${contextPath}${themePath}/images/win_06.gif" width="18" height="15" /></td>  
            <td class="win_box_d"> </td>  
            <td valign="top"><img src="${contextPath}${themePath}/images/win_08.gif" width="18" height="15" /></td>  
          </tr>  
    </table>  
    </div>  
</div>  
    </body>  
</html>  
<script>  
    $("#punish_type").change(function(){  
        if($("#punish_type").val()==1){  
            alert($("#punish_type").val())  
            $("#punish_money").show();  
            $("#traintime").hide();  
              
        }else if($("#punish_type").val()==2){  
            $("#chengfai").text("培训时间:")  
                    alert($("#punish_type").val())  
            $("#punish_money").hide();  
            $("#traintime").show();  
        }  
    })  
      
      
</script>  
  
主界面:  
  
punish.jsp  
  
<%@ 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);  
%>  
<!-- 通用变量 -->  
<link rel="stylesheet" href="${contextPath}${themePath}/css/layout.css" type="text/css"></link>  
<link rel="stylesheet" href="${contextPath}${themePath}/css/zfba.css" type="text/css"></link>  
<link rel="stylesheet" href="${contextPath}${themePath}/css/win.css" type="text/css"></link>  
<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>  
<!-- loading  -->  
<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>  
  
  
  
safeIndex.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/include.inc"%>  
<link rel="stylesheet" href="${contextPath}${themePath}/css/layout.css" type="text/css"></link>  
<html>  
    <head>  
  
    </head>  
      
  
    <body>  
        <center>  
            <!-- 窗体容器开始 -->  
            <div class="container">  
                <!-- 头部 -->  
                <jsp:include page="include/safe_top.jsp" />  
                <div id="main">  
                    <div class="main_box03">  
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">  
                            <tr>  
                                <td>  
                                    <table width="100%" border="0" cellspacing="0" cellpadding="0">  
                                        <tr>  
                                            <td width="10">  
                                                <img src="${contextPath}${themePath}/images/title_a.jpg"  
                                                    width="10" height="41" />  
                                            </td>  
                                            <td class="main_box01_t" id="menuInfo">  
                                                整改反馈列表  
                                            </td>  
                                            <td width="10" align="right">  
                                                <img src="${contextPath}${themePath}/images/title_c.jpg"  
                                                    width="10" height="41" />  
                                            </td>  
                                        </tr>  
                                    </table>  
                                </td>  
                            </tr>  
                            <tr>  
                                <td height="505px" valign="top">  
                                    <div class="zfba_menu"  
                                        style="height: 505px; width: 17%; float: left;">  
                                        <iframe height="100%" width="100%" border="0" scrolling="no" frameborder="0" src="include/left.jsp" noresize="true" name="left"  name="left">  
                                        </iframe>  
                                          
                                    </div>  
                                    <div class="content"  
                                        style="width: 82%; height: 505px; float: right">  
                                        <iframe height="505px" width="100%" border="0"  id="main" name="main"                                          
                                        frameborder="0" src="safe_check.jsp" style="overflow-y:scroll; overflow-x:hidden;table-layout: fixed;word-wrap:break-word;word-break:break-all">  
                                        </iframe>  
                                          
                                    </div>  
                                </td>  
                            </tr>  
                            <tr>  
                                <td height="10">  
                                    <table width="100%" border="0" cellspacing="0" cellpadding="0">  
                                        <tr>  
                                            <td width="10">  
                                                <img src="${contextPath}${themePath}/images/box_b01.jpg"  
                                                    width="10" height="10" />  
  
                                            </td>  
                                            <td width="10100" class="box_b02"></td>  
                                            <td width="10" align="right">  
                                                <img src="${contextPath}${themePath}/images/box_b03.jpg"  
                                                    width="10" height="10" />  
                                            </td>  
                                        </tr>  
                                    </table>  
                                </td>  
                            </tr>  
                        </table>  
                    </div>  
                </div>  
                <div style="height: 10px"></div>  
                <div class="footer">  
                    <jsp:include page="include/footer.jsp" />  
                </div>  
            </div>  
        </center>  
    </body>  
</html>  
<script>  
function showMenuInfo(obj){  
    alert(obj.text())  
    $("#menuInfo").text(obj.text());  
}  
</script>  
X
赞助一下:
    支付宝    微信    QQ红包

打开支付宝扫一扫

发表评论

电子邮件地址不会被公开。 必填项已用*标注

00:00 / 00:00
顺序播放