Just follow these steps to make it work:
jQuery.getJSON("http://subodh.blog.com/servlet?user=subodh&responseType=JSON",
function(str) {
alert(str.user.fname);
});
Look at this link for details jQuery.getJSON.
http://subodh.blog.com/servlet?user=subodh&responseType=JSON this could be replaced by your service returning JSON response.
That's it you are done. :)
- Compose your response as an JSON let say responseObject variable represent this JSON string/object
- Wrap the JSON response as an argument to a method call e.g. helloMethod(responseObject); where helloMethod is the method name
- Define this method(helloMethod) which handles this response in the client side
- assume JSON Object as str = {"user":{"fname":"subodh","lname":"gupta","type":"blog","category":"tech"}}
- handleUser(str);
- function handleUser(str){ alert(str.user.fname);}
jQuery.getJSON("http://subodh.blog.com/servlet?user=subodh&responseType=JSON",
function(str) {
alert(str.user.fname);
});
Look at this link for details jQuery.getJSON.
http://subodh.blog.com/servlet?user=subodh&responseType=JSON this could be replaced by your service returning JSON response.
That's it you are done. :)
Comments
Post a Comment