Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling Rest webservice using JQuery Ajax call , web service is returning JSON string
    primarykey
    data
    text
    <p>I have made a Rest Web Service:</p> <pre><code>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 } } </code></pre> <p>When I go to internet explorer &amp; type this in the address bar:</p> <pre><code>http://localhost:8080/nagarro-0.0.1-SNAPSHOT/MyRESTApplication/dealInfo/2 </code></pre> <p>It is giving me:</p> <pre><code>{'name':'Peter Norton', 'age':50} </code></pre> <p>But when I call it using an ajax call in a JQuery method. e.g.</p> <pre><code>$.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); } }); </code></pre> <p>I am getting an Error in this call. </p> <p><img src="https://i.stack.imgur.com/RZFU9.png" alt="enter image description here"></p> <p>When I am debugging using F12 in IE, I am getting following as well </p> <pre><code>"Invalid JSON: {\'name\':\'Peter Norton\', \'age\':50}" </code></pre> <p><strong>Would anybody tell me what could be the problem in my call.</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload