I have made a Rest Web Service:
package org.jboss.samples.rs.webservices;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@Path("/MyRESTApplication")
public class HelloWorldResource {
@GET()
@Produces("application/json")
@Path("/dealInfo/{dealId}")
public String sayHello(@PathParam("dealId") int dealId) {
System.out.println("dealid......"+dealId);
switch(dealId) {
case 1 :System.out.println("employee id.....");
return "{'name':'George Koch', 'age':58}";
case 2:
return "{'name':'Peter Norton', 'age':50}";
default:
return "{'name':'unknown', 'age':-1}";
} // end of switch
}
}
When I go to internet explorer & type this in the address bar:
http://localhost:8080/nagarro-0.0.1-SNAPSHOT/MyRESTApplication/dealInfo/2
It is giving me:
{'name':'Peter Norton', 'age':50}
But when I call it using an ajax call in a JQuery method. e.g.
$.ajax({
type: "GET",
url: "http://localhost:8080/nagarro-0.0.1-SNAPSHOT/MyRESTApplication/dealInfo/2",
data: "",
success: function(resp){
// we have the response
alert("Server said123:\n '" + resp + "'");
},
error: function(e){
alert('Error121212: ' + e);
}
});
I am getting an Error in this call.
When I am debugging using F12 in IE, I am getting following as well
"Invalid JSON: {\'name\':\'Peter Norton\', \'age\':50}"
Would anybody tell me what could be the problem in my call.