how to make an Ajax call Play 2.6

45 views
Skip to first unread message

James Goodman

unread,
Oct 17, 2017, 4:11:37 AM10/17/17
to Play Framework
Hey guys,

I am stuck with no vision when making an Ajax call - I am pretty new to this and Play...

So I make a call to my J.S via a form like this

<button type="button" class="btn btn-default" id="submitBtn" name="submitBtn" onclick="validatePassword()">Submit</button>

it tests my passwords to make sure they match, and that works

My next step is I want to see if the email address is in the database before signing up and I do not want to refresh the page..so I have this as the helper in my view


@()

@helper.javascriptRouter("jsRoutes")(
routes.javascript.SignupController.signup

)

inside the above JS script I have this (which I copied from here as an example way of calling it https://www.playframework.com/documentation/2.6.x/JavaJavascriptRouter#Embedded-router)


$.ajax(jsRoutes.controllers.SignupController.signup())
.done( /*...*/ )
.fail( console.log("failed here"));

Now at this stage I was expecting to see some sort of print out, but I cannot see any print out anywhere - can you give me an idea as to where I am going wrong?

I really wish there was more fuller examples on the play docs.

amertum

unread,
Oct 17, 2017, 3:09:02 PM10/17/17
to Play Framework
Try this :

$.ajax(jsRoutes.controllers.SignupController.signup().url)

I've added .url

Look in the generated code by helper.javascriptRouter to see what's the javascript looks like.
Reply all
Reply to author
Forward
0 new messages