ajax - RestEasy method receiving null as parameters in case of POST method and working fine for Get Method -


i have created resteasy web service , using get method , passing parameters services using uri http://localhost:8080/rest/search?name=foo , accessing parameters using @queryparam , working fine: note: calling web service using ajax call

@get @path("/search") @consumes({"application/xml", "application/json", "text/plain"}) @produces( mediatype.text_plain) public jsonarray getdetails(@queryparam("name") string name) {          //my code here  } 

my ajax call

$.ajax({     type : 'get',         url : searchurl,         headers : { 'sm_user' : userid  },         datatype : 'json',         success : function(data) { 

now have change method post , in case not accepting uri paramenter have tried in different way like: passing value through ajax data. ajax call:

 $.ajax({     type : 'post',     url : searchsuppurl,     headers : { 'sm_user' : userid},     contenttype: "application/json",     data: { 'name' : 'foo'},     datatype : 'json' success : function(data) { 

web service code:

@post @path("/search") //@consumes({"application/x-www-form-urlencoded"}) @consumes({"application/xml", "application/json", "text/plain"}) @produces( mediatype.text_plain) public jsonarray getdetails(string name) { 

the data available service not correctly formatted have sysout

system.out.println("name...." +name); 

instead of printing name....foo printing name....name=foo

i not getting missing suggestions...

thanks in advance

i want string value, use

@consumes({"application/x-www-form-urlencoded"}) 

like trying do. rid of contenttype in ajax request (it default application/x-www-form-urlencoded. , add @formparam annotation resource method

public jsonarray getdetails(@formparam("name") string name) { 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -