java - Ajax Client for jersey rest service returns success response but no value -


here service -

@get     @path("{id}/json")     @produces("application/json")     public response getimagebyidjson(@pathparam("id") int imageid) {         //return this.getinagebyid(imageid);         list<image> imagelist = null;          try {             imagelist = intlxbusiness.getallimage();         } catch (sqlexception e) {             e.printstacktrace();         }          image returnimage = null;         (image image : imagelist) {              if (image.getimageid() == imageid)                 returnimage = image;         }          // creates responsebuilder         responsebuilder builder = new responsebuilderimpl();         // sets header of return data         builder.header("content-type", "application/json");         // sets response code 200         builder.status(response.status.ok);         // allows cross domain requests origin         builder.header("access-control-allow-origin", "*");         // adds result data response         builder.entity(returnimage);         // creates response         return builder.build();     } 

here ajax call -

<head>     <meta charset="utf-8">     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>     <script type="text/javascript">     $.ajax({         type:"get",         url: "http://localhost:8888/intellixwebapi/intellixservices/activeimage/1/json",          headers : {accept : "application/json","access-control-allow-origin" : "*"}         datatype:"json",         crossdomain: true,         success: function(data){             alert(data);         },         error: function(msg){             alert("error! \n" + msg);         }     });  </script>   

here response screen shot -

image response

but there no data.

when calling through browser; getting following response -

in json

{"image-id":1,"image-name":"visakha star","image-url":"f:/recieved file/vishaka.jpg","image-description":"description star"} 

in xml --

<images image-id="1" debug="true"> <script id="firebuglite" firebugignore="true" extension="chrome"/> <image-name>visakha star</image-name> <image-url>f:/recieved file/vishaka.jpg</image-url> <image-description>description star</image-description> </images> 

please tell me wrong. service used in cors. have added required information in service method.

edit---

if using ajax code -

$.ajax({   type:"get",     url: "xxxx",      cache: false,     async: false,     crossdomain: true,     jsonp: true,     jsonpcallback: "callback",     contenttype: "application/json; charset=utf-8",     datatype: "jsonp",       success: function(data){         alert(data);     },     error: function(jqxhr, textstatus, errorthrown){alert('fail event '+errorthrown)} }); 

then getting response looks in following images-

error picture

response pivture

response xml correct.

thanks kumar shorav


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -