0
$('#fillUpdateOwnerButton').on('click', function () {
                var email = $('#eMailUpdateOwner').val();
                console.log(email);
                $.ajax({
                    type: 'POST',
                    url: "updateBusOwnerDetailsServlet",
                    data: {"emailForSearch": email},
                    success: function (msg) {
                        alert(msg);
                    }

above is the code between the <Script> tag, that console.log() also prints nothing and below I mention how I try to get data by Servlet, but this is not working, it prints null,

System.out.println(request.getParameter("emailForSearch"));
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Sachithra Wishwamal
  • 117
  • 1
  • 2
  • 10
  • I copied your client-side code to an `index.jsp` file and completed it with appropriate surrounding HTML, and I copied your line of Java code to an `updateBusOwnerDetailsServlet.jsp` file placed inside the `<% ... %>` JSP scriptlet tags. I also had to create a `WEB-INF/web.xml` deployment descriptor file to map the URL pattern `/updateBusOwnerDetailsServlet` to the `/updateBusOwnerDetailsServlet.jsp` file. After doing all of the above, everything worked perfectly. Hence, the code you've posted is perfect, and the problem on your end must be related to the surrounding server setup. – bgoldst Sep 09 '16 at 14:58
  • If you provide more information about your server setup, particularly the JSP file names and paths you have in your webapp, and what you're doing with your `web.xml` descriptor, then we can look into this further. – bgoldst Sep 09 '16 at 15:00

2 Answers2

0

Try changing your ajax call with this :

$(document).ready( function() {
    $('#fillUpdateOwnerButton').on('click', function () {
        var email = $('#eMailUpdateOwner').val();
        console.log(email);
        $.ajax({
            type: 'POST',
            url: "updateBusOwnerDetailsServlet",
            data: {"emailForSearch": email},
            success: function (msg) {
                alert(msg);
            }
        });
    });
});

You have to load ajax in page on document ready . Checked from my end working fine. Let me know for any issues

Abhijeet
  • 4,069
  • 1
  • 22
  • 38
0

i think fillUpdateOwnerButton this is your button's id if this is so

try to change

$('#fillUpdateOwnerButton').on('click', function () {}

in this replace $('#fillUpdateOwnerButton') to $('#document') or immediate parent container's id of your button

since you have not pasted your code I can help you out till here

try this or pase full code

Shantaram Tupe
  • 1,646
  • 3
  • 16
  • 42