html <link rel="import" href="../polymer/polymer-element.html"> <link rel="import" href="../iron-ajax/iron-ajax.html"> <dom-module id="my-component"> <template> <form> </form> </template> <script> class MyComponent extends Polymer.Element { static get is() { return 'my-component'; } _registerUser() { const username = this.$.username.value; const password = this.$.password.value; const ajax = this.$.ajax; ajax.url = "/api/user"; ajax.method = "POST"; ajax.body = { username, password }; ajax.generateRequest(); } } window.customElements.define(MyComponent.is, MyComponent); </script> </dom-module> import spark.Spark; import com.google.gson.Gson; public class Main { public static void main(String[] args) { Spark.post("/api/user", (req, res) -> { String username = req.queryParams("username"); String password = req.queryParams("password"); return new Gson().toJson("User registered successfully"); }); } }


上一篇:
下一篇:
切换中文