hello have server , should make request on button pressed have call method , when works should parse json doesnt see controller method main method available
how call
<input type="submit" onclick="@routes.login.resp()" value="login" > because not worrking cannot resolve symbol
get /login controllers.login.main() my controller:
package controllers; import play.libs.f; import play.libs.ws; import play.mvc.controller; import play.mvc.result; public class login extends controller { public static result main() { return ok(views.html.login.render()); } public static f.promise<result> resp() { string feedurl="http://validate.jsontest.com/?json=%7b%22key%22:%22value%22%7d"; final f.promise<result> resultpromise = ws.url(feedurl).get().flatmap( new f.function<ws.response, f.promise<result>>() { public f.promise<result> apply(ws.response response) { return ws.url(response.asjson().findpath("empty").astext()).get().map( new f.function<ws.response, result>() { public result apply(ws.response response) { return ok("size" + response.asjson().findpath("count").asint()); } } ); } } ); return resultpromise; } } view:
<!-- author: w3layouts author url: http://w3layouts.com license: creative commons attribution 3.0 unported license url: http://creativecommons.org/licenses/by/3.0/ --> <!doctype html> <html> <head> <title>login</title> <meta charset="utf-8"> <link rel="stylesheet" media="screen" href="@routes.assets.at("stylesheets/stylelogin.css")"> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="application/x-javascript"> addeventlistener("load", function() { settimeout(hideurlbar, 0); }, false); function hideurlbar(){ window.scrollto(0,1); } </script> <!--webfonts--> <link href='http://fonts.googleapis.com/css?family=open+sans:600italic,400,300,600,700' rel='stylesheet' type='text/css'> <!--//webfonts--> </head> <body> <!-----start-main----> <div class="main"> <div class="login-form"> <h1>member login</h1> <div class="head"> <img src="@routes.assets.at("images/user.png")" alt=""/> </div> <form> <input type="text" class="text" value="username" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'username';}" > <input type="password" value="password" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'password';}"> <div class="submit"> <input type="submit" onclick="@routes.login.main()" value="login" > </div> </form> </div> <!--//end-login-form--> <!-----start-copyright----> <!-----//end-copyright----> </div> <!-----//end-main----> </body> </html> i not sure if parse json properly,how make proper get,post requests , parse
as far know onclick attribute call function in javascript. if want specify url need put form tag action attribute <form action="@routes.login.main()">.
the default html form tag send get. if want send post have specify via additional method="post" <form action="@routes.login.main()" method="post">. have change routing too: post /login controllers.login.main(). if want post login data i'd recommend use post because data including password turns in query string of url.
additionally @routes.login.main() method returns login view return ok(views.html.login.render());. instead should evaluate form data sending.
Comments
Post a Comment