Home > Web Front-end > JS Tutorial > How does jquery convert an array into a string and pass it to the server for processing_jquery

How does jquery convert an array into a string and pass it to the server for processing_jquery

WBOY
Release: 2016-05-16 16:50:32
Original
1311 people have browsed it

jquery converts the array into a string and then transmits it to the server (after jquery converts the array into a string, the format is such as 1, 2, 3, speed, rewr)

Copy code The code is as follows:

define(function(require, exports, module) {

var Notify = require('common/bootstrap-notify') ;

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) {
Notify.danger('No' name is selected);
return;
}

if (!confirm('The selected 'ids.length' should be deleted ' name '? ')) {
return ;
}

$element.find('.btn').addClass('disabled');

Notify .info('Deleting ' name ', please wait.', 60);
var values=ids.toString();
$.post($btn.data('url'), {ids :values}, function(){
window.location.reload();
});

});

};

}) ;

Receive the string passed by jquery, parse it into an array, and then convert the array into a list collection
Copy code The code is as follows:

/**
* Delete private messages in batches.
*/
@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);//The array is converted into a 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("An exception occurred while adding a private message, Cause: ", e);
return this.errorResponse(e.getMessage());
}
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template