Using javascript routes in Play Framework 2

I am trying to make ajax calls using jsRoutes in a gaming infrastructure. It works great for queries that take no parameters, but when I try to call a controller method that takes Long as a parameter, it fails without an error message. Here is some code to better explain.

Users.java controller class:

public static Result addToShortList(long id) { return whatever } 

Conf / Routes

 POST /shortList/:userId controllers.Users.addToShortList(userId: Long) 

In the Application.java controller file, I return jsRoutes as follows:

 public static Result javascriptRoutes() { response().setContentType("text/javascript"); return ok(Routes.javascriptRouter("jsRoutes", controllers.routes.javascript.Application.frontpage(), ... controllers.routes.javascript.Users.addToShortList(), controllers.routes.javascript.Users.removeFromShortList())); } 

Now in my javascript I can use jsRoutes by doing the following:

 jsRoutes.controllers.Users.addToShortList(id).ajax({ success : function(data) { alert(data); }, error : function(err) { //code always ends up here, with the err giving no eerror message at all! alert(err); } }); 

It seems that this functionality of the playback platform is poorly documented, or maybe I'm just blind to find nothing ...

Thanks for any help!

+8
javascript ajax
source share
1 answer

Good, I thought to myself. The problem was that I used a long (primitive) controller method. Why is this a problem that I do not know.

+5
source share

All Articles