<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TechPitcher &#187; jQuery</title>
	<atom:link href="http://www.techpitcher.com/category/jquery/feed" rel="self" type="application/rss+xml" />
	<link>http://www.techpitcher.com</link>
	<description></description>
	<lastBuildDate>Mon, 20 Dec 2010 10:28:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>JSON communication between server and client Part1</title>
		<link>http://www.techpitcher.com/json-communication-between-server-and-client-part1.html</link>
		<comments>http://www.techpitcher.com/json-communication-between-server-and-client-part1.html#comments</comments>
		<pubDate>Wed, 26 Aug 2009 15:35:33 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://techpitcher.com/?p=170</guid>
		<description><![CDATA[JSON (JavaScript Object Notation) provides lightweight data exchange between server and client. It is human readable.
Sending data in JSON format from server to client:
There are APIs present for many languages (Java, ASP, Flex, C, C++ etc). With the help of these APIs, we can get JSON representation for data or objects. This data can be [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.json.org/" target="_blank">JSON</a> (JavaScript Object Notation) provides lightweight data exchange between server and client. It is human readable.<br />
Sending data in JSON format from server to client:<br />
There are APIs present for many languages (Java, ASP, Flex, C, C++ etc). With the help of these APIs, we can get JSON representation for data or objects. This data can be send to client just like some other data.<br />
On the client side browser can handle this format and one can retrieve the information send from server.<br />
I am writing code sample for spring framework</p>
<pre class="brush: java;">
public void getJSONInfo(HttpServletRequest request, HttpServletResponse response) throws Exception {
    JSONObject result = new JSONObject();
    try {
        Object obj = new Object();
        // To get JSON data from obj
       JSONObject jsonObj = JSONObject.fromObject(obj);
       result.put(&quot;result&quot;, &quot;success&quot;);
       result.put(&quot;jsonInfo&quot;, jsonObj);
   } catch (Exception e) {
       result.put(&quot;result&quot;, &quot;error&quot;);
  } finally {
      // Write this jsonObj in HttpServletResponse
      response.getWriter().print(result);
      response.flushBuffer();
   }
}
</pre>
<p>While on the client side, I am using <a href="http://jquery.com/" target="_blank">jquery</a> to make AJAX request,</p>
<pre class="brush: jscript;">
function getJSONInfo() {
    $.ajax({
       url: '../location?q=getJSONInfo',
       type: &quot;POST&quot;,
       cache: false,
       dataType: &quot;json&quot;,
       success: function(response){
           alert(response.jsonInfo);
       },
       error: function(msg){
       }
    });
}
</pre>
<p>As we can see from the example, an ajax request is made to get JSONInfo and result is displayed in popup window.</p>
<p>Sending data in JSON format from client to server will be covered in part2</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techpitcher.com/json-communication-between-server-and-client-part1.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

