JQueryAjax interacts with the background to encapsulate js applications

Source: Internet
Author: User
Common jspaggingjsvarcurrentPage1; varmaxpagesize; varmessage; varurl & quot; varparam & quot; add a callback function -- modify and delete the functionsaveData (param, url, message, addDt
// Public js pagging. jsvar currentPage = 1; var maxpagesize; var message; var url = ""; var param = ""; // Add a callback function -- modify, delete the function saveData (param, url, message, addDtaFun, tb) {if (confirm (message) {$. ajax ({url: url, type: "post", data: param, // remember, data is the transmitted parameter dataType: "json", error: function (XMLHttpRequest, textStatus, errorThrown) {// alert ("========" + XMLHttpRequest. redayState + "|" + textStatus + "|" + e RrorThrown) ;}, success: function (data) {if (data = 1) {alert ("operation successful! "Commandid tb.html (" "); addDtaFun () ;}else {alert (" operation failed ") ;}}}// query data of all departments function addDept (deptId, url) {var param = ""; $. ajax ({url: url, type: "post", data: param, // remember, data is the transmitted parameter dataType: "json", beforeSend: function (){}, error: function (XMLHttpRequest, textStatus, errorThrown) {// alert ("======" + XMLHttpRequest. redayState + "|" + textStatus + "|" + errorThrown);}, success: function (data) {$. each (data, function (I, d) {// selectvar $ 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, // remember, data is the transmitted parameter 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) ;}})} // query all employees of the Ministry of Security and environment: function addcheckPersons (id) {var url = contextPath + "/emp/empCheckPerson. action "; $. ajax ({url: url, type: "post", // data: param, // remember, data is the transmitted parameter 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) ;}})} // pagingFunc (tb, addDtaFun) functions tb.html (""); // clear the content addDtaFun ();} // jump to function goPage () {var page = $ ("# page "). val (); // the page number is legal. if (valPagesize (page, maxpagesize) = true) {paging (page );}} // function valPagesize (size, maxpagesize) {if (size> = 1 & size <= maxpagesize) {return true;} else if (size <1) {alert ("page cannot be less than 1"); $ ("# page "). focus (); return false;} else if (size> maxpagesize) {alert ("the number of input pages cannot exceed the maximum"); $ ("# page "). focus (); return false;} else {alert ("the number of pages entered is invalid"); $ ("# page "). focus (); return false ;}}


Reference file include. inc <% @ page language = "java" import = "java. util. * "pageEncoding =" UTF-8 "%> <% @ taglib prefix =" c "uri =" http://java.sun.com/jsp/jstl/core "%> <% // context path String contextPath = request. getContextPath (); // topic path String themePath = "/template/themes/default"; pageContext. setAttribute ("themePath", themePath); pageContext. setAttribute ("contextPath", contextPath); %>
 
 
 
 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.