#ajax
index.js
$("#init").on('click', function(){
$.ajax({
type: "GET",
url: "/init",
dataType : "json"
}).then(
function(data){
$("#foodList").empty();
for (var i = 0; i < data.length; i++) {
$("#foodList").append(
"<tr>"
+"<td> <a class='btn btn-default' href='/actor/detail?id='" +data[i].id+ "'>" + data[i].name + "</a></td>"
+"<td class='item-price'>" + data[i].price + "</td>"
+"<td class='item-category'>" + data[i].classification + "</td>"
+"<td>" + data[i].vendor + "</td>"
+"<td>"
+"<form action='/delete/' method='post'>"
+"<input class='btn btn-warning' type='submit' value='delete'>"
+"</form>"
+"</td>"
+"</tr>"
);
}
}
)
});
FoodController.java
public Result init() {
FoodService service = new FoodService();
return ok(Json.toJson(service.findByIdLimitNum()));
}
routes
GET /init controllers.FoodController.init
#getのパラメータ取得
Controller.java
String id = request().getQueryString("id");