You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
--- /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") ...
-
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: