Here is the scenario I have a REST service defined as follow:
@Path("/company/{companyName}/sessions")
public class RESTSessionController {
RESTService service = new RESTService();
@GET
@Produces({"application/json"})
@Path("/{username}/{password}")
public Result getFriend(@PathParam ("companyName") String companyName ,
@PathParam ("username") String username,
@PathParam ("password") String password){
System.out.println(companyName);
return service.login(username,password);
}
}
To call this I have a javascript as follow:
$.ajax({
url: 'http://localhost:8888/rest/company/hertz/sessions/amir/help',
dataType: 'json',
data: null,
success: function(data) {
$("#abc").html(dumpObj(data,"Result",'',0));
}
});
This works fine and I get this back:
{"code":"200","description":"Amir is now logged in.","payload":{"@type":"xs:string","$":"Amir123"}}
which is perfectly fine.
Now I'm trying to go one step further and call my service using an object so I changed my code to:
$.ajax({
qObj={username:"Amir",password:"123",companyName:"hertz"}
url: 'http://localhost:8888/rest/company/',
dataType: 'json',
data: JSON.stringify(qObj),
success: function(data) {
$("#abc").html(dumpObj(data,"Result",'',0));
}
});
And it won't work.
My question is simple, how to I call a REST service with parameter in the path (or without it) using jquery/javascript?
Thx for the help
Amir