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.
//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 =
(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.
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. ...
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:" +...
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. ...
ajax servlet code...
Front desk ajax request Receive requests in the background Read files in a folder @ResponseBody public void getPic(HttpServletRequest request,HttpServletResponse response,@RequestPa...
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...
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...
Traditional:true, : Prevents deep serialization and prevents data from being available in 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...