I can't seem to figure out how to perform ajax calls in Play. I've used other frameworks before and it was just a matter of placing something like remote="true"
on the form.
How do you use ajax in Playframework? What am I doing something wrong here?
Code:
/**
* AJAX Form
*/
@helper.form(action = routes.SomeCtrl.ajaxForm()) {
<p>
<input type="submit">
</p>
}
/**
* myview.scala.js
*/
@(implicit r: RequestHeader)
$(function() {
alert("AJAX is working!");
})
/**
* SomeCtrl ajaxForm def
*/
def ajaxForm() = Action { implicit request =>
Ok(views.js.myfolder.myview()).as("text/javascript")
// just testing it
}
/**
* routes
*/
POST /assets/javascripts/ajax-form.js controllers.SomeCtrl.ajaxForm()
if you want include the js the you have to
<script type="text/javascript" charset="utf-8" src="@routes.SomeCtrl.ajaxForm()"></script>
according to your code your js will act as a page, and the content written on your js will shown on web as it is written.
for ajax refrence you can check http://www.playframework.com/documentation/2.2.x/ScalaJavascriptRouting
and check this question Play 2.x: How to make an AJAX request with a common button