0

I wrote a simple RESTful web service with wink, where there is an interface returning JSONARRAY. And I can get the json by directly typing the address in the browser. Then, I developed a html page and used jquery's $.getJSON to call the web service, however, in debugging I can see that the service method is invoked but the client page can't get json data, how could it be? Here is the method at server:

@GET
@Produces(MediaType.APPLICATION_JSON)
public JSONArray getAllBook(){

    JSONArray result = new JSONArray();

    Collection<Book> books = BookStore.getInstance().getBooks();

    for(Book book : books){
        try{
                result.put(BookStore.createJSONObject(book));

        }catch(JSONException e){
            e.printStackTrace();
        }
    }

    return result;
}

And here is the js code:

var url = "http://localhost:8080/WinkExBookLib/rest/book";
$.getJSON(url,function(data){
alter("aaa");
alter(data);
});
Sunny W.
  • 1
  • 1
  • Sounds to me like JQuery and not Wink's question. I suggest changing title and editing tags to include jquery. – Tarlog Mar 18 '13 at 08:12
  • In addition, I advise to sniff traffic, to see if the json content really arrives to the page. You can do it in several ways, including the browser's developer tools for IE or Chrome, or Firebug plugin for FF, or Fiddler sniffing tool. – Tarlog Mar 18 '13 at 08:13
  • Thanks for your answer. I used FireBug and found that the page had received Response back after invoking jQuery.getJSON().But there is no data(JSON) in the Response and the callback function couldn't run.I still can't resolve the error.Could you give me more instructions. – Sunny W. Mar 20 '13 at 06:15
  • Now it sounds like a server side problem. Do you really get to your method? Any exceptions in log? – Tarlog Mar 20 '13 at 06:29
  • I'm sure the request can get to the method, and there is no exception in log. – Sunny W. Mar 20 '13 at 07:08
  • I'm not sure whether the page got the JSON data. I can only see 'Headers' and 'Cache' tab for the Response from FireBug. – Sunny W. Mar 20 '13 at 07:16

0 Answers0