How does jquery turn an array into a string and pass it to the server for processing

  • 2020-03-30 02:46:48
  • OfStack

Jquery converts the array to a string and then passes it to the server (after jquery converts the array to a string, the format is 1,2,3, speed, rewr)
 
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(' Not selected ' + name); 
return ; 
} 

if (!confirm(' This one will delete the selected one ' + ids.length + ' article ' + name + ' ? ')) { 
return ; 
} 

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

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

}); 

}; 

}); 

Take the string from jquery, parse it into an array, and then convert the array into a list
 
 
@RequestMapping(value = "/delete", method = {RequestMethod.GET,RequestMethod.POST}) 
public ResponseEntity<AjaxPostResponse> delete(HttpServletRequest request) { 
//List of private message ids to be deleted
String messageIds = ServletRequestUtils.getStringParameter(request, "ids", ""); 
String[] messageList=messageIds.toString().split(","); 
List<String> messageIdList = Arrays.asList(messageList);//Convert an array to 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 articles: