Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[#1103] added documentation in ajax.textile for jsRoute tag

  • Loading branch information...
commit b21249d76df2c3448a97b6a3ff66f5956f585f13 1 parent 4f37f29
@opensas opensas authored mbknor committed
Showing with 22 additions and 1 deletion.
  1. +22 −1 documentation/manual/ajax.textile
View
23 documentation/manual/ajax.textile
@@ -2,7 +2,7 @@ h1. Ajax in the Play framework
The Play framework allows you to easily perform Ajax requests, and is shipped with "jQuery":http://jquery.com by default. This section describes how to effectively use "jQuery":http://jquery.com within the framework.
-The Play framework also comes with the handy @jsAction@ tag to transparently get a method definition from the controller.
+The Play framework also comes with the handy "jsAction":tags#jsaction tag to transparently get a method definition from the controller.
h2. <a name="jsaction">Using jQuery with the jsAction tag</a>
@@ -42,6 +42,27 @@ bc. $.post(listAction(), function(data) {
$('#result').html(data);
});
+h2. <a name="jsaction">Using jQuery with the jsRoute tag</a>
+
+To have more control on the generated route, you also have the "jsRoute":tags#jsroute tag, which is similar to the **#{jsAction /}** tag but it returns an object containing both the function which consctructs the URL based on the server action, and the corresponding HTTP method (GET, POST, etc.).
+
+Example:
+
+bc. PUT /users/{id} Users.update
+
+Then, in a template:
+
+bc. <script type="text/javascript">
+ var updateUserRoute = #{jsRoute @Users.update(':id') /}
+ $.ajax({
+ url: updateUserRoute.url({id: userId}),
+ type: updateUserRoute.method,
+ data: 'user.name=Guillaume'
+ });
+</script>
+
+With this approach, you won't have to update your templates in case you decide to change the HTTP method in the routes file.
+
p(note). **Continuing the discussion**
Handle %(next)"Internationalization":i18n%.
Please sign in to comment.
Something went wrong with that request. Please try again.