$("#submit").on('click',function () { $.ajax({ url:"http://localhost:8080/webtest/service", method:"POST", dataType:"application/json", success:function () { alert("Ajax request success"); }, error:function () { alert("look at the response headers for error!") } }); }); }); <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Tests</title> <script src="jquery-3.1.0.js"></script> <script src = "https://code.jquery.com/jquery-1.11.3.js"></script> <script src = "https://code.jquery.com/jquery-2.1.4.js"></script> </head> <body> <form"> <label for = "username">UserName:</label> <input id = "username"><br> <label for = "email">Email:</label> <input id = "email" type="email"><br> <label for = "password">Password:</label> <input id = "password" type="password"><br> <input id = "submit" type="button" value="Send!"> </form> <script src="requests.js"></script> </body> </html> @WebServlet(name = "webService" , urlPatterns = "/service") public class WebServiceDemo extends HttpServlet { response.setHeader("Access-Control-Allow-Origin","*"); response.getWriter().print("In the if else DO POST METHOD"); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { **//When the server starts i got response from here!** response.getWriter().print("Hello from servlet"); } } Meet with Ajax requests. What is wrong with this code? When you try to submit a request for an error report! I get a refund from server 200! But the Jquery Ajax code of the error function with an alert is output! Why
