【发布时间】:2015-05-25 02:47:08
【问题描述】:
我想通过 ajax 搜索一个帐户。我的客户端有这个。
<form id="fetchAccount">
<input type="search" name="id"/>
<input type="submit"/>
</form>
<script>
$(document).ready(function(){
$('#fetchAccount').on('submit', function(e){
var data = $(this).serialize();
var header = $("meta[name='_csrf_header']").attr("content");
var token = $("meta[name='_csrf']").attr("content");
$.ajax({
data:data,
type:"PUT",
url:"fetchAccout",
dataType : 'json',
contentType : 'application/json; charset=utf-8',
beforeSend: function(xhr){
xhr.setRequestHeader(header, token);
},
success: function(response){
console.log(response);
}
});
e.preventDefault();
});
});
</script>
在控制器上
@RequestMapping(value="/fetchAccout", method=RequestMethod.PUT,
produces= MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Account fetchAccount(@RequestParam(value="id", required=false) Long id){
Account account = null;
if(id != null)
account = custService.findAccountById(id);
return account;
}
我有一个 200 HTTP 响应。我怀疑我的错误是在客户端。我什至无法在成功功能中发出警报。
【问题讨论】: