play framework javascript Routing Failed to load resource

Jakob Abfalter

I am trying to make some Javascript Rounting in my Play Framework app and am running into some errors:

I have a button with the id #next which should use Ajax to load some new image and text into a div named #content.

In my Application.java I have implemented the following two methods:

public static Result nextUser(int i) {
    return ok(content.render(users.get(i)));
}

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

Made this content.scala.html file:

@(user: User)
<img id="user" src="@routes.Assets.at(user.getImg())" />
<h2>@user.getStatus()</h2>

Added this into to the routes file:

GET        /nextuser                    controllers.Application.nextUser(i: Int)

GET        /assets/javascripts/routes   controllers.Application.javascriptRoutes()

And then tried this Javascript code:

<script type="text/javascript" src="@routes.Application.javascriptRoutes()"></script>
<script>
    var userIndex = 1;

    $("#next").click(function() {
        jsRoutes.controllers.Application.nextUser(userIndex).ajax({
        success : function(data) {
            $("#content").html(data);
        },
        error: function(err) {

        }
        });
    });

</script>

In the Application.java file in the javascriptRoutes Method the controllers.routes. can not be found.

Does anybody know what is causing the error?

Edit:

I could solve the initial error thanks to this: Unable to resolve reverse routing methods in IntelliJ

Now it looks like this:

enter image description here

The nextUser Method cannot be found even when cleary defined.

When I compile the application using activator compile and run it using activator run my chrome console looks like this:

http://i.gyazo.com/34581c81beda3520f927991c6a0c554f.png

so still the routes file somehow cant be found.

Jakob Abfalter

Ok I could fix the problem thanks to this:

Can't get javascriptRoutes to work with Play Framework 2

The problem was the order in my routes document. As soon as I switched the assets declaration before the javascript routes it worked:

# Javascript Router
GET        /assets/javascripts/routes        controllers.Application.javascriptRoutes()

# Map static resources from the /public folder to the /assets URL path
GET        /assets/*file                controllers.Assets.at(path="/public", file)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Failed to load resource: the server responded with a status of 404 (Not Found) on routing

From Dev

Rails unobtrusive javascript - Failed to load resource

From Java

Play Framework: Arrow ("->") in routing

From Dev

Failed to load .js resource

From Dev

Failed to load resource in HTML

From Dev

Glide failed to load resource

From Dev

GlideException: Failed to load resource

From Dev

IDEA Failed to load resource

From Dev

Load a Javascript in another Javascript in Play-scala Framework

From Dev

Failed to load resource in AngularJS project

From Dev

Failed to load resource with Websocket application

From Dev

Failed to load resource in Node JS

From Dev

Angular and html - Failed to load resource

From Dev

GitHub Pages Failed to load resource

From Dev

Suppress Load of media resource failed

From Dev

iframe on Safari: Failed to load resource

From Dev

Failed to load resource, blank page

From Dev

Play Framework: NoSuchFieldError when reverse routing

From Dev

scala play framework reverse routing and controllers

From Dev

Failed to load resource: the server responded with a status of 406 (Not Acceptable) during javascript api call

From Dev

JavaScript failed to load resource: file not found, but the file is a Laravel auto-generated view

From Dev

Error in Chrome only: XMLHttpRequest failed to load resource

From Dev

AJAX Post Test Method Failed to load resource

From Java

Failed to load resource css file. Freemarker

From Dev

IONIC: Failed to load resource: unsupported URL

From Dev

Bokeh Inline Embedding, 'Failed to load resource'

From Dev

webpack dev server Failed to load resource

From Dev

Failed to load resource while consuming OData service

From Dev

Laravel Failed to Load vendor resource from server?

Related Related

  1. 1

    Failed to load resource: the server responded with a status of 404 (Not Found) on routing

  2. 2

    Rails unobtrusive javascript - Failed to load resource

  3. 3

    Play Framework: Arrow ("->") in routing

  4. 4

    Failed to load .js resource

  5. 5

    Failed to load resource in HTML

  6. 6

    Glide failed to load resource

  7. 7

    GlideException: Failed to load resource

  8. 8

    IDEA Failed to load resource

  9. 9

    Load a Javascript in another Javascript in Play-scala Framework

  10. 10

    Failed to load resource in AngularJS project

  11. 11

    Failed to load resource with Websocket application

  12. 12

    Failed to load resource in Node JS

  13. 13

    Angular and html - Failed to load resource

  14. 14

    GitHub Pages Failed to load resource

  15. 15

    Suppress Load of media resource failed

  16. 16

    iframe on Safari: Failed to load resource

  17. 17

    Failed to load resource, blank page

  18. 18

    Play Framework: NoSuchFieldError when reverse routing

  19. 19

    scala play framework reverse routing and controllers

  20. 20

    Failed to load resource: the server responded with a status of 406 (Not Acceptable) during javascript api call

  21. 21

    JavaScript failed to load resource: file not found, but the file is a Laravel auto-generated view

  22. 22

    Error in Chrome only: XMLHttpRequest failed to load resource

  23. 23

    AJAX Post Test Method Failed to load resource

  24. 24

    Failed to load resource css file. Freemarker

  25. 25

    IONIC: Failed to load resource: unsupported URL

  26. 26

    Bokeh Inline Embedding, 'Failed to load resource'

  27. 27

    webpack dev server Failed to load resource

  28. 28

    Failed to load resource while consuming OData service

  29. 29

    Laravel Failed to Load vendor resource from server?

HotTag

Archive