In a development project, the foreground value is passed to the background. Sometimes there are two or more values in the JSP form, and all values are included. If one value is 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 ");}});}