Cool solution for Cross domain

Just follow these steps to make it work:
  1. Compose your response as an JSON let say responseObject variable represent this JSON string/object
  2. Wrap the JSON response as an argument to a method call e.g. helloMethod(responseObject); where helloMethod is the method name
  3. Define this method(helloMethod) which handles this response in the client side
Lets take complete working sample:
  1. assume JSON Object as str = {"user":{"fname":"subodh","lname":"gupta","type":"blog","category":"tech"}}
  2. handleUser(str);
  3. function handleUser(str){ alert(str.user.fname);}
just to complete the solution look at call below:

function(str) {

Look at this link for details jQuery.getJSON. this could be replaced by your service returning JSON response.

That's it you are done. :)


Popular posts from this blog Connection reset

Hide empty last column from Table/Tree Viewer

Spring: implements interface not working in @Controller