Batch processing when using AJAX commit operations

Source: Internet
Author: User

1. Front Page Ajax submission data:

The following are examples of bulk deletions:

functionDeleteaudio () {varAudionums = [];  for(vari = 0; I < $ ("input[type=checkbox]:checked"). Length; i++) {Audionum= $ ("input[type=checkbox]:checked"). EQ (i). Val (); Audionums[audionums.length]=Audionum; }
Converting data to a JSON array submission
varJsonstring =json.stringify (audionums); $.ajax ({URL:"Operateaudio.shtml", type:"POST", DataType:"JSON", data: {"Audionum": jsonstring, "method": "Deleteaudio"}, Success:function(data) {if(Data.success = = 1) {alert ("Delete Data succeeded"); Location.reload (); } } }); }

2. Background servlet Code:

String Audiojson = Request.getparameter ("Audionum"); //converts the resulting string to a JSON arrayJsonarray Jsonarray =Jsonarray.fromobject (Audiojson);  for(inti = 0; I < jsonarray.size (); i++) {
Jsonarray.getstring (i) Gets the JSON array for each item of the Date audiodate
=Dao.querydata (jsonarray.getstring (i)); File File=NewFile ("mp3/" +audiodate); if(File.exists ()) {file.delete (); }} PrintWriter out=Response.getwriter (); Out.write ("{\" success\ ": 1}"); Out.close ();
Jsonarray needs a json-lib jar package, altogether 6 are:
1) Commons-beanutils-1.9.3.jar
2) Commons-collections-3.2.jar
3) Commons-lang-2.5.jar
4) Commons-logging-1.2.jar
5) Ezmorph-1.0.6.jar
6) Json-lib-2.4-jdk15.jar
These 6 packages have version issues and it's best to use these versions that bloggers share.

Batch processing when using AJAX commit operations

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.