user1909647
user1909647

Reputation:

Enable to send data to servlet using AjAx and post method

function validate (user_value){
    var name = user_value;
    $.ajax({
        url:"ggs.erm.servlet.setup5.AjaxS",
        data:{ namee :name},
        success:function(){
            alert("worked");
        }
    });
}

This is my Code. Is something wrong with it?? Any kind of syntax or semantics error.
Problem:Not able to send parameter to servlet in URL.?????

Upvotes: 0

Views: 2104

Answers (2)

Jai
Jai

Reputation: 74738

It seems that your function is in doc ready handler check this out and see if helps:

 function validate (user_value){
    var name = user_value;
    $.ajax({
       url:"ggs.erm.servlet.setup5.AjaxS",
       type:'POST', //<-----------------added this
       data:{ namee :name},
       success:function(data){
         if(data){
          alert("worked");
         }
       },
       error:function(){
         alert('not worked.');
       } 
    });
}

$(document).ready(function(){
   // your other code stuff for calling the function
});

Upvotes: 0

Minko Gechev
Minko Gechev

Reputation: 25682

If you want your servlet's doPost method to handle the request you should add property type with value post.

function validate (user_value){
    var name = user_value;
    $.ajax({
        url:"ggs.erm.servlet.setup5.AjaxS",
        data:{ namee :name},
        type: 'post',
        success:function(){
            alert("worked");
        }
    });
}

This way your Ajax request will be post instead of get (the default one).

Upvotes: 1

Related Questions