Share

From this page you can share Get cross-site JSON via HTTP with GWT and the GWT Designer by Instantiations to a social bookmarking site or email a link to the page.
Social WebE-mail
Enter multiple addresses on separate lines or separate them with commas.
(Your Name) has forwarded a page to you from Ajaxonomy
(Your Name) thought you would like to see this page from the Ajaxonomy web site.

Get cross-site JSON via HTTP with GWT and the GWT Designer by Instantiations

Tagged:  

The GWT is a great development tool for designing Ajax applications. Since JSON is a great way to exchange data from the server to the client, in many cases, it is good to find a tutorial combining the two. Well, over at the Giant Flying Saucer blog they have put together a nice tutorial about cross-domain JSON and GWT. The tutorial is written for users of the GWT Designer, but even if you don't use that tool this tutorial has some good information.

Below is an excerpt from the tutorial.

If your a web developer then chances are pretty good you've already heard of and possibly used JSON. In a nutshell, JSON is a lightweight way to exchange data. In the second tutorial we did our communications to and from the server via RPC (Remote Procedure Calls). This time we'll modify the code to use JSON instead and call a third-party server (we will simulate this with a Python web server on the same computer).
Assuming you've got everything ready go ahead and open the project now. One of the first things the GWT JSON tutorial shows is how simple the JSON format is:

XML:

[
  {

    "symbol": "BA",
    "price": 87.86,
    "change": -0.41
  },
  {

    "symbol": "KO",
    "price": 62.79,
    "change": 0.49
  },
  {

    "symbol": "JNJ",
    "price": 67.64,
    "change": 0.05
  }
]

You can see JSON is just name/value pairs and human readable. Its simpler than XML and less verbose (less eyeball noise). Keep in mind though if you do need XML support that GWT offers that as well. Today though we are focusing purely on JSON.
So how do we actually get the JSON from the server to the client? Well, fortunately GWT provides everything we need in the form of the HTTP client classes. There are three items in particular we'll use from there:
1. RequestBuilder and calling the "sendRequest" method

2. RequestCallback which (remember the callback we had in the second tutorial?) will call "onResponseReceived" on a successful callback or "onError" if something goes wrong.
- Note: Toward the end of this tutorial we will replace the RequestBuilder code.

You can read the full tutorial here.