S
S
s2018-05-20 19:33:04
JavaScript
s, 2018-05-20 19:33:04

Why am I not getting a post request in the servlet using $.ajax?

I can not figure out why the post-request does not get to the servlet by url. Maybe something with ajax'om wised up?

function validate(event) {


        if(document.getElementById("inputPassword").value !== document.getElementById("inputPasswordConfirm").value) {
            alert("Passwords are different!!!")
            event.preventDefault();
        } else {
            var data = {
                login: document.getElementById("field1").value,
                name: document.getElementById("field2").value,
                surname: document.getElementById("field3").value,
                email: document.getElementById("field4").value,
                icq: document.getElementById("field5").value,
                gender: document.getElementById("name").value,
                password: document.getElementById("inputPassword")
            };alert(data);
            $.ajax({

                type: 'POST',
                url: '/newuserprocessing',
                data: data,

                success: function (data) {
                    alert(data);
                },
                error: function (data) {
                    alert(data);
                }
            });
        }


    }

@WebServlet("/newuserprocessing")
public class RegistrationServlet extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println(req.getParameter("data"));
        resp.getWriter().print("Welcome, you are in servlet!");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    System.out.print("Ты в Пост запросе");


    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2018-05-21
@solovladys

- your scripts are crashing, check what causes an error, most likely password: document.getElementById("inputPassword") .value
- there are no Ajax requests in the network, so the script does not reach the Ajax request call.
- use console.log() for debugging, it's more informative.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question