views:

59

answers:

2

hi,

im trying to POST (cross domain) some data to a jersey web service and retrieve a response (a GenericEntity object). The post successfully gets mapped to my jersey endpoint however when i pull the parameters from the request they are empty..

$ .ajax({
   type: "POST",
   dataType: "application/json; charset=utf-8",
   url: jerseyNewUserUrl+'?jsoncallback=?',
   data:{'id':id, 'firstname':firstname,'lastname':lastname},
   success: function(data, textStatus) {
   $('#jsonResult').html("some data: " + data.responseMsg);
            },
   error: function ( XMLHttpRequest, textStatus, errorThrown){
    alert('error');
     }
  });

this is my jersey endpoint..

@POST
    @Produces( { "application/x-javascript", MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
    @Path("/new")
    public JSONWithPadding addNewUser(@QueryParam("jsoncallback")
    @DefaultValue("empty")
    final String argJsonCallback, @QueryParam("id")
    final String argID, @QueryParam("firstname")
    final String argFirstName, @QueryParam("lastname")
    final String argLastName)

is there something missing from my $.ajax call?

+1  A: 

Try this:

$ .ajax({
   type: "POST",
   dataType: "jsonp",
   jsonp: "fooCallBackFunction",
   url: jerseyNewUserUrl,
   data:{'id':id, 'firstname':firstname,'lastname':lastname},
   success: function(data, textStatus) {
   $('#jsonResult').html("some data: " + data.responseMsg);
            },
   error: function ( XMLHttpRequest, textStatus, errorThrown){
    alert('error');
     }
  });
orokusaki
no, still returning empty params inside my endpoint, am i setting up the json object correctly?i cant see anything else
combi001
@ccduga, I'm sorry. To be honest I've never used Jersey, and it looks to me that your jQuery code is fine. I was hoping I could conquer this one from the front-end. One more thing to try though. Try my latest update to the answer.
orokusaki