我有Ajax代碼爲400錯誤的請求錯誤去春來RestController
/**
* Ajax Logic for submitions
* */
$.ajax({
contentType : 'application/json; charset=utf-8',
type: 'POST',
url: '/domain/insert/',
dataType : 'json',
data : 'firstName:' + $("#first_name").val() /*+ "&lastName;=" + $("#lastName").val() + "&email;=" + $("#email").val()*/,
success : function(callback){
console.log("Data inserted.........");
},
error : function(){
console.log("Error.........");
}
});
越來越控制檯出把儘可能
POST http://localhost:8080/domain/insert/ 400 (Bad Request)
Z.cors.e.crossDomain.send @ common.min.js:3
J.extend.ajax @ common.min.js:3
t.length.t.steps.onStepChanged @ forms_wizard.min.js:34
J.event.dispatch @ common.min.js:2
m.handle @ common.min.js:2
J.event.trigger @ common.min.js:2
J.fn.extend.triggerHandler @ common.min.js:2
(anonymous function) @ wizard_steps.min.js:1
c @ common.min.js:2
d.fireWith @ common.min.js:2
(anonymous function) @ common.min.js:2
c @ common.min.js:2
d.fireWith @ common.min.js:2
a @ common.min.js:2
c @ common.min.js:2
d.fireWith @ common.min.js:2
d.fire @ common.min.js:2
J.extend.dequeue @ common.min.js:2
i.complete @ common.min.js:2
c @ common.min.js:2
d.fireWith @ common.min.js:2
I.l @ common.min.js:1
J.fx.tick @ common.min.js:3
forms_wizard.min.js:47
Error.........
在RestController我的插入方法是
@RequestMapping(value = "/question/", headers="Accept=*/*", consumes="application/json", method = RequestMethod.POST)
public ResponseEntity<Void> insert(@RequestBody User user) {
System.out.println("Creating " + user.getFirstName());
service.save(user);
return new ResponseEntity<Void>(HttpStatus.CREATED);
}
好吧,如果我使用Postman將POST數據發送到控制器,它會成功,但通過上述ajax代碼,我會得到400錯誤.....