ajax pass an array of issues from the foreground to the background

Hello Hello everyone: I still love Shenyangjava trainingThe Tsai, brought to you today is from the front desk ajax Detailed analysis and backstage pass to an array of problems.

Welcome to the Markdown editor

//batch deletion
$(‘body’).on(“click”, “#deleteBatch”, function () {
var cbs = KaTeX parse error: Expected '}', got 'EOF' at end of input: …h; i++){ if((cbs[i]).prop(“checked”)){
var q = ( c b s [ i ] ) . p a r e n t ( ) . p a r e n t ( ) . c h i l d r e n ( ) ; q = N u m b e r ( (cbs[i]).parent().parent().children(); q = Number( (q[q.length-1]).html());
cbsArr.push(q);
}
}
cbsArr = toString(cbsArr);
console.log(cbsArr);

	$.ajax({
		url:'NewsDeleteBatchServlet',
		type:'post',
		async:true,
		// traditional attributes of ajax
		//traditional:true,
		data:{
			cbsArr:cbsArr
		},
		success:function(){
			//window.location.replace('NewsTablePage.jsp');
		}
	})
})

By checking the box, acquisition parameters, batch operation.
jq obtained is set or array, is transmitted to the background by ajax, background using req.getParameter () to receive this parameter can not be obtained and found to give the null.
after a search on the network, a solution was found
a Program: ajax To attribute String of data format, we can put the code prior to cbsArr type String, and then further transfer parameters can be modeled in JAVA Arrays.. toString () to write a that is:

function toString(arr){
var b = ‘’;
for(var i = 0 ; i < arr.length ;i++){
if(arr[i] != null){
b = b +"’"+ arr[i] +"’";
if( i == arr.length-1){
return b;
}
b = b + ‘,’;
}
}
}
Thus, the background data can be obtained a
Scheme II: We can add to a traditional ajax: true attribute.
traditional:true
query that this property, this property defaults to false, jquery depth will serialize this object, PHP, etc. to accommodate the frame, we can stop the sequence of depth by setting to true tradtional
After setting the traditional attributes, data types can be passed to a collection or array. Background through
String[] arrs = req.getParameterValues(“cbsArr”);
getParameterValues ​​receiving array or collection parameters.
so that after the encounter, when a plurality of transfer id box would not have to fight the foreground or the background spilt toString direct use of traditional ajax properties, pass over an array, a background direct List idList to accept. Very convenient.

Intelligent Recommendation

ajax pass array to python background

Purpose: pass [1,2,3,4] such an array to the background I was struggling with this issue for a while, the first was to use the json string Later found request.args.getlist() This mentality collapsed. ...

Through ajax ------ the background dynamically generates html tags for the foreground, and transmits the background data to the foreground (pass parameter)

The key codes in the background are as follows: Front desk corresponding method and key code for receiving parameters: function detail(vendors,product_name,s){ console.log ("Manufacturer:" +...

Use modelAndView and ModelMap to pass values ​​from the background to the foreground

modelAndView: This object contains a model attribute and a view attribute. --model: Actually a ModelMap type. In fact, ModelMap is a subclass of LinkedHashMap. --view: Contains some view information. ...

More Recommendation

The foreground ajax gets the file stream upload file from the background

Front desk ajax request Receive requests in the background Read files in a folder @ResponseBody     public void getPic(HttpServletRequest request,HttpServletResponse response,@RequestPa...

Using Ajax in the SSM framework to transfer data from the foreground to the background

Use process The first step: the introduction of jQuery library Step 2: Build the most basic structure The third step: receiving data in the background be careful The above example is the data passed i...

springMVC jumps to the foreground from the background, but Ajax does not enter the callback function

Reprinted at: http://www.cnblogs.com/sxdcgaq8080/p/5765648.html Question 1: uses the background accessed by ajax, the background executes normally, and returns data normally, but cannot enter the ajax...

Pass the array with ajax to the background: traditional: true,

Traditional:true, : Prevents deep serialization and prevents data from being available in the background...

jQuery ajax pass json array to the background

jQuery ajax pass json array to the background The front end code is as follows: Background code: Here is the params, which is data:{params:JSON.stringify(arr)}. The key of the aqx passed in the parame...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top