Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Using JS routes in Playframework 2.x (Scala)
package controllers
object MyController extends Controller {
def add() = Action { implicit request =>
Form( tuple ( "user" -> number ) ).bindFromRequest.fold(
errors => BadRequest,
t => {
Ok("Add id: " + t)
}
)
}
def delete(input : String) = Action { implicit request =>
try {
val id = java.lang.Long.parseLong(input)
Ok("Delete id: " + id)
} catch { case _ : Throwable => BadRequest }
}
}
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
# ... Normal routes
# JS Routes:
PUT /comment/add controllers.MyController.add
DELETE /comment/:id controllers.MyController.delete(id)
@(id : Int)
@helper.javascriptRouter("myRoutes")(
routes.javascript.MyController.add,
routes.javascript.MyController.delete
)
<script type="text/javascript">
function addSomeAjax() {
myRoutes.controllers.MyController.add().ajax({
data: { user: @id },
success: function(data) {
alert("Succes!111one");
}
})
}
function deleteSomeAjax() {
myRoutes.controllers.MyController.delete(@id).ajax({
success: function(data) {
alert(data);
}
});
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.