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);
});