ブラウザで json 応答の URL を直接入力すると、正しい応答が JSON でブラウザに出力されますが、ボタンをクリックすると同じ URL が呼び出され、応答が空のように見えます。
これが私のコントローラーです:
@RequestMapping(value="/ShowAllCustomers", method = RequestMethod.GET)
public @ResponseBody Customer AllCustomersList() {
Customer customer=customerService.findById(1);
return customer;
}
そして、ここで私は応答を得ようとしています:
<script type="text/javascript">
function startAjax() {
$.ajax({
type : 'GET',
url : 'customers/ShowAllCustomers',//this is url mapping for controller
dataType: 'json',
success : function(response) {
alert(response);
alert(response.first_name);
//this response is list of object commming from server
}
});
}
</script>
押されたボタンのコードは次のとおりです。
<input type="button" value="Customers" onclick="startAjax();"/>
しかし、ボタンをクリックしても、画面に警告メッセージが表示されません。
解決策を教えてください。