Last active
April 4, 2018 14:06
-
-
Save 0xh3xa/6af1b38adcf88a9d19abe415af3022c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <script> | |
| function hideErrorMsg(){ | |
| $("#errorTextFieldID").hide(); | |
| } | |
| $(document).ready(function(){ | |
| hideErrorMsg(); | |
| }); | |
| function validate() { | |
| var textField = $("#textFieldID"); | |
| $.ajax({ | |
| url: 'servlet_pattern_url', | |
| type: "GET", | |
| data: { | |
| element: textField.val() | |
| }, | |
| success: function (data) { | |
| if(data.found){ | |
| textField.select(); | |
| $("#errorTextFieldID").show(); | |
| } | |
| } | |
| }); | |
| return false; | |
| } | |
| </script> | |
| </head> | |
| <body> | |
| <form> | |
| <input type="text" id="textFieldID" onblur="validate()" onfocus="hideErrorMsg()"/> | |
| <span id="errorTextFieldID">enter another input, it's duplicated in db</span> | |
| </form> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //How to make an Ajax request from html to servlet. | |
| //NOTE: Found is a variable in Servlet: | |
| public void doGet(HttpRequest request, HttpResponse response) throws Exception{ | |
| String element = request.getParameter("element"); | |
| //TODO check the element Does it found in db or not? | |
| boolean found = db.check(); | |
| response.getWriter().write(found); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment