How to put List from controller to view using Ajax Play framework 2.2.5

I have using Ajax js in Play framework I should change existing list list when select option onchange,I want to change existing list when user choose another option it will show only list where id are equal but I have make all of them now I should only replace response how to change existing list by ajax response list ?I only check it with alert and it works

GET    /rests                           controllers.NewOrder.restoran(id:Int)

code:
neworder.scala.html:

@(ordertype: List[OrderType],restaurants: List[Restaurant],section: List[RestaurantSection],place: List[Place]);

<script type="text/javascript" src="@routes.NewOrder.javascriptRoutes"></script>



<script type="text/javascript" charset="utf-8">



var showinfo = function(id) {
var num1 = id;



jsRoutes.controllers.NewOrder.restoran(id).ajax({
success: function(data) {
/*$("#sections").html(data);*/

    alert(data);




var select = $('#sections');
select.empty().append('<option value="">data</option>');






},
error: function() {
alert("Error!")
}
})
};



</script>

                        @for(gesture <- restaurants){
                            <option value="@gesture.id">@gesture.title</option>

                                }

                        </select>





  <select name ="OrderType" id="sections">

                            @for(gesture <- section){
                                <option value="@gesture.id">@gesture.title</option>

                            }

                            </select>

ajax_result.scala.html:

@(result: List[RestaurantSection])
<select name ="ss" id="dd" ">

    @for(gesture <- result){
        <option value="@gesture.id">@gesture.title</option>

    }

</select>
@result

controller:

public static Result restoran(int id ) {
       // Integer answer = Integer.valueOf(num1) + Integer.valueOf(num2);
        List<RestaurantSection> ids = RestaurantSection.findByRestaurant(id);




        return ok(views.html.officiant.ajax_result.render(ids));
    }

public static Result javascriptRoutes() {
        response().setContentType("text/javascript");
        return ok(
                Routes.javascriptRouter("jsRoutes",
                        // Routes
                        controllers.routes.javascript.NewOrder.restoran()
                )
        );
    }


Source: ajax

Leave a Reply