ajax - Using javascript routes in Play Framework 2 - Stack Overflow

I'm attempting to make ajax calls using jsRoutes in play framework. It works fine for requests tha

I'm attempting to make ajax calls using jsRoutes in play framework. It works fine for requests that does not take any parameters, but when I try to call a controller method which takes a Long as a param, it fails with no error message. Here's some code to explain it better.

Controller class Users.java:

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

conf/routes

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

In Application.java controller file i return the jsRoutes like this:

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 the 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 the this functionality of the play framework is poorly documented, or maybe I'm just blind not to find it anywhere...

Thanks for any help!

I'm attempting to make ajax calls using jsRoutes in play framework. It works fine for requests that does not take any parameters, but when I try to call a controller method which takes a Long as a param, it fails with no error message. Here's some code to explain it better.

Controller class Users.java:

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

conf/routes

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

In Application.java controller file i return the jsRoutes like this:

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 the 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 the this functionality of the play framework is poorly documented, or maybe I'm just blind not to find it anywhere...

Thanks for any help!

Share Improve this question asked Sep 17, 2012 at 11:52 Runar HalseRunar Halse 3,55810 gold badges41 silver badges60 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Ok, figured the problem out myself. The problem seemed to be that I used long(primitive) in the controller method. Why this is a problem I do not know.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745241625a4618215.html

相关推荐

  • ajax - Using javascript routes in Play Framework 2 - Stack Overflow

    I'm attempting to make ajax calls using jsRoutes in play framework. It works fine for requests tha

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信