1
如何在控制器類中獲取公司名稱,當我打印字符串cname = req.getParameter(「companyName」)時,它顯示未定義。如何從JS函數獲取數據到控制器類
添加快照以供參考。
編輯公司控制器
@RequestMapping(value = "/editCompany", method = RequestMethod.GET)
public ModelAndView editCompany(ModelAndView model, HttpServletRequest req, HttpServletResponse res) {
String cname = req.getParameter("companyName");
System.out.println(cname);
//int companyId = companyDAO.GetCompanyId(req.getParameter("companyName"));
Company company = companyDAO.getInfo(req.getParameter("companyName")) ;
model.addObject("company", company);
model = getDropdownList(model);
model.setViewName("editCompany");
return model;
}
JS
$("#EditBtn").click(function(e) {
var companyName=$("#table tr.trActive td:first").html();
$
.ajax({
type : "GET",
url : "editCompany?companyName="+companyName,
data : JSON.stringify(companyName),
contentType: "text/plain",
success : function(data) {
alert('sucess');
//viewCompanyViaAjax();
},
error : function() {
alert('Error occured');
}
});