Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manual/working/scalaGuide/advanced/routing/ScalaJavascriptRouting.md #1272

Open
garbagetown opened this issue Feb 8, 2016 · 0 comments
Open
Milestone

Comments

@garbagetown
Copy link
Member

--- /Users/garbagetown/Desktop/2.2.0/manual/working/scalaGuide/advanced/routing/ScalaJavascriptRouting.md   2016-02-07 23:19:03.000000000 +0900
+++ //Users/garbagetown/Desktop/2.4.x/manual/working/scalaGuide/advanced/routing/ScalaJavascriptRouting.md  2016-02-07 23:19:30.000000000 +0900
@@ -1,3 +1,4 @@
+<!--- Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com> -->
 # Javascript Routing

 The play router is able to generate Javascript code to handle routing from Javascript running client side back to your application. The Javascript router aids in refactoring your application. If you change the structure of your URLs or parameter names your Javascript gets automatically updated to use that new structure.
@@ -25,11 +26,10 @@
 A router resource can be generated by creating an action that invokes the router generator. It has a similar syntax to embedding the router in a template:

     def javascriptRoutes = Action { implicit request =>
-      import routes.javascript._
       Ok(
-        Routes.javascriptRouter("jsRoutes")(
-          Users.list,
-          Users.get
+        JavaScriptReverseRouter("jsRoutes")(
+          routes.javascript.Users.list,
+          routes.javascript.Users.get
         )
       ).as("text/javascript")
     }
@@ -50,13 +50,21 @@
       .done( /*...*/ )
       .fail( /*...*/ );

-The router also makes a few other properties available including the ``url``, the ``type`` (the HTTP method), the ``absoluteURL`` and the ``webSocketURL``. For example the above call to jQuery's ajax function can also be made like:
+The router also makes a few other properties available including the ``url`` and the ``type`` (the HTTP method). For example the above call to jQuery's ajax function can also be made like:

     var r = jsRoutes.controllers.Users.get(someId);
     $.ajax({url: r.url, type: r.type, success: /*...*/, error: /*...*/ });

 The above approach is required where other properties need setting such as success, error, context etc.

+The ``absoluteURL`` and the ``webSocketURL`` are methods (not properties) which return the complete url string. A Websocket connection can be made like:
+
+    var r = jsRoutes.controllers.Users.list();
+    var ws = new WebSocket(r.webSocketURL());
+    ws.onmessage = function(msg) {
+            /*...*/
+    };
+
 ## jQuery ajax method support

 > **Note:** Built-in support for jQuery's ajax function will be removed in a future release. This section on the built-in support is provided for reference purposes only. Please do not use the router's ajax function in new code and consider upgrading existing code as soon as possible. The previous section on using the router documents how jQuery should be used.
@@ -66,4 +74,3 @@
 To define this function, in your action pass the ``ajaxMethod`` method parameter, eg:

     Routes.javascriptRouter("jsRoutes", Some("myAjaxFunction") ...
-

@garbagetown garbagetown added this to the 2.4.x milestone Feb 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants