How does jquery convert an array into a string to the server and process _ jquery

Source: Internet
Author: User
This article mainly introduces how jquery transfers an array into a string to the server for processing. If you need it, refer to jquery to convert the array into a string and then upload it to the server (after jquery converts the array into a string, format: 1, 2, 3, speed, rewr)

The Code is as follows:


Define (function (require, exports, module ){

Var every Y = require ('common/bootstrap-every y ');

Module. exports = function ($ element ){

$ Element. on ('click', '[data-role = batch-delete]', function (){

Var $ btn = $ (this );
Name = $ btn. data ('name ');

Var ids = [];
$ Element. find ('[data-role = batch-item]: checked'). each (function (){
Ids. push (this. value );
});

If (ids. length = 0 ){
Using Y. danger ('unspecified' + name );
Return;
}

If (! Confirm ('Do you want to delete the selected '+ ids. length +' bar '+ name +? ')){
Return;
}

$ Element. find ('. btn'). addClass ('Disabled ');

Policy.info ('deleting '+ name +', please wait. ', 60 );
Var values = ids. toString ();
$. Post ($ btn. data ('url'), {ids: values}, function (){
Window. location. reload ();
});

});

};

});


Receives the string passed by jquery, parses it into an array, and converts it to a list set.

The Code is as follows:


/**
* Batch Delete private messages.
*/
@ RequestMapping (value = "/delete", method = {RequestMethod. GET, RequestMethod. POST })
Public ResponseEntity delete (HttpServletRequest request ){
// List of private message IDs to be deleted
String messageIds = ServletRequestUtils. getStringParameter (request, "ids ","");
String [] messageList = messageIds. toString (). split (",");
List MessageIdList = Arrays. asList (messageList); // convert the array to list
Logger.info ("------------" + messageIds );
Logger.info ("------------" + messageList [0]);
Try {
Boolean opStatus = messageManager. delete (messageIdList );
Logger.info ("delete private message: opStatus ={}", opStatus );
Return this. okResponse (opStatus );
} Catch (Exception e ){
Logger. error ("exception occurred when adding a private message, Cause:", e );
Return this. errorResponse (e. getMessage ());
}
}

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.