Using the form serialization method provided by jQuery can solve the problem of passing values in a JSP form. The following is an example. You can refer to the following in the development project, pass the foreground value to the background. Sometimes there are two or all values in the JSP form. If the values are uploaded one by one, it is definitely not a good solution, therefore, using the form serialization method provided by jQuery can solve this problem well. It can also be encapsulated into common functions. After successful execution, you can call their respective callback functions to implement their respective functions.
The Code is as follows:
Function queryUserInfo (actionUrl, formId, fun) {var params = new Object (); // declare an array $. each ($ ("#" + formId ). serializeArray (), function (index, param) {params [param. name] = param. value; // serialized form}); params ['time'] = new Date (); // 1 $. ajax ({url: basePath + actionUrl, data: params, // No 1, you can write it like this ("#" + formId ). serializeArray () type: 'post', ype: 'json', async: false, // indicates synchronization. The following code success will be executed only after the server returns data: function (obj) {fun (actionUrl, formId, obj) ;}, error: function () {alert ("Access exception ");}});}
Another method:
Function setUserInfo (actionUrl, userid, username, fun) {var params = new Object (); // declare the array params ['user. id'] = userid; params ['user. name'] = username; $. ajax ({url: actionUrl, data: params, // No 1, you can write it like this ("#" + formId ). serializeArray () type: 'post', ype: 'json', async: false, // indicates synchronization. The following code success will be executed only after the server returns data: function (obj) {fun (actionUrl, formId, obj); // call the callback function}, error: function () {alert ("Access exception ");}});}