1

Here is my Ajax code:

var email="abc@abc.com";    

    $.ajax({
        url : "ships",
        data : "{email" + email.toString() + "}",
        success : function(data){
            alert(data)
        },
        error : function(data) {
            console.log("error:", data);
        },

        type : "post"
    });

And here is my Java Servlet code:

protected void doPost(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {

    System.out.println(request.getParameter("email"));


}

I CANNOT read data in Java Servlet The console prints out the following value for email:

null

I am using Tomcat 7

Can anyone please tell me what i am doing wrong and why i cannot read data in Java Servlet_

Kunal Vashist
  • 2,380
  • 6
  • 30
  • 59

1 Answers1

2

The property data of the param object is a JavaScript object, so to send a parameter named EmailAddress you would do:

...
url : "ships",
data : {
    EmailAddress: email.toString()
},
success : function(data){
    ...
Gustav Barkefors
  • 5,016
  • 26
  • 30