【发布时间】:2016-02-10 13:17:14
【问题描述】:
我有大约 15 - 20 个数据变量,要通过下面的 ajax 函数。
有没有最简单的方法可以从 ajax 传递多个变量,并以一种简单的方式在 Controller 类下面获取这些多个变量??
Jsp页面:
function getAssignedParticularTable(){
$.ajax({
type: "POST",
url: "assignedParticularTable.html",
data: "operation=assignedParticularTable",
success: function(response){
var obj = JSON.parse(response);
$("#table2").html("");
var tr="";
tr+="<thead><tr><th>Sl no.</th><th>Fee Particular Name</th><th>Amount</th><th>Selection</th></tr></thead><tbody>";
for (var i = 0, j=0; i < obj.length; i++){
tr+="<tr>";
tr+="<td>" + (++j) + "</td>";
tr+="<td>" + obj[i].Name + "</td>";
tr+="<td><input type='text' id='amount' name='amount' value='0'/></td>";
tr+="<td><input type='checkbox' id='check' name='fee_particular_ids' value='"+obj[i].Id+"' /></td>";
tr+="</tr>";
}
$("#table2").append(tr);
}
});
}
控制器类:
@RequestMapping(value = "/assignedParticularTable.html", method = RequestMethod.POST)
public @ResponseBody String assignedParticularTable(@RequestParam HashMap<String, String> map, HttpSession session) {
System.out.println("operation: " + map.get("operation"));
return "";
}
【问题讨论】:
标签: javascript jquery json ajax spring-mvc