LoginSignup
0
0

More than 5 years have passed since last update.

メモ

Last updated at Posted at 2018-01-21

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");
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0