Play framework version is 2.2.6
jQuery
$('#fridgeSearchInputField').keyup(function () {
var $text = $(this).val();
$.ajax({
type: 'GET',
url: '@routes.controllers.Application.ajaxAutocomplete()',
data: $text,
success: function (data) {
// success result
}
});
});
Routes file
GET /:ingredientName controllers.Application.ajaxAutocomplete(ingredientName: String)
Method in Application controller
public static Result ajaxAutocomplete(String ingredientName){
String s = request().body().asText(); //I guess something here is wrong
System.out.println(s);
return ok("");
}
The problem is that when I print s variable in play console it prints out null. What is wrong in my code? And how can I get the text from input field through the request in order to use it later? Thanks