进行 ajax 调用后,我收到错误 405 方法不允许。我正在使用 Spring 3.0.1,Spring-web 3.0.1。
这是控制器映射
@Controller 公共类 AjaxController {
@RequestMapping(value = "/ajaxaction",
method = RequestMethod.POST,
headers ="content-type=application/json")
public @ResponseBody Collection<Employee> serveAjaxRequest(@RequestBody ReqParam reqParam){
List<Employee> empList = new ArrayList<Employee>();
System.out.println("Req obj:: " + reqParam.getA() + " " + reqParam.getB()
+ " " + reqParam.getC() + " " + reqParam.getD() + " " + reqParam.getE());
Employee e1 = new Employee();
e1.setFirstName("Vaibhav");
e1.setLastName("Raj");
e1.setEmail("vraj3@sapient.com");
e1.setTelephone("1111111111");
e1.setReturnMessage("Message one!!");
Employee e2 = new Employee();
e1.setFirstName("Ajay");
e1.setLastName("Singh");
e1.setEmail("asingh@gmail.com");
e1.setTelephone("2222222222");
e1.setReturnMessage("Message two!!");
empList.add(e1);
empList.add(e2);
return empList;
}
)
和ajax调用的Jquery代码:
功能:提交Ajax(){
$('#g').bind('click', function(evt) {
alert($('form').serialize());
formData = $('form').serialize();
$.ajax({
url: "/ajaxaction.html",
type: 'POST',
dataType: 'json',
data: formData,
success: function(data) {
alert(data);
},
error: function(){
alert("Error!!");
}
});
});