Muaz Usmani
Muaz Usmani

Reputation: 1318

RPC call to external server

I am a new bie on GWT, I wrote an application on abc.com, I have another application i.e. xyz.com, xyz.com?id=1 provides me a data in json format, I was thinking to find a way that how to get that json file in abc.com via RPC call, because I have seen tutorials in which RPC calls are used to get data from its server. any help will be appreciated.

EDIT

I am trying to implement this in this StockWatcher tutorial

I changed my code slightly change to this

private static final String JSON_URL = "http://localhost/stockPrices.php?q=";

AND

 private void refreshWatchList() {
            if (stocks.size() == 0) {
                return;
            }

            String url = JSON_URL;

            // Append watch list stock symbols to query URL.
            Iterator iter = stocks.iterator();
            while (iter.hasNext()) {
                url += iter.next();
                if (iter.hasNext()) {
                    url += "+";
                }
            }

            url = URL.encode(url);

            MyJSONUtility.makeJSONRequest(url, new JSONHandler() {

                @Override
                public void handleJSON(JavaScriptObject obj) {
                    if (obj == null) {
                        displayError("Couldn't retrieve JSON");
                        return;
                    }
                    updateTable(asArrayOfStockData(obj));
                }
            });


        }

before when I was requesting my url via RequestBuilder it was giving me an exception Couldn't retrieve JSON but now JSON is fetched and status code is 200 as I saw that in firebug but it is not updating on table. Kindly help me regarding this.

Upvotes: 1

Views: 179

Answers (1)

user1258245
user1258245

Reputation: 3639

First, you need to understand the Same Origin Policy which explains how browsers implement a security model where JavaScript code running on a web page may not interact with any resource not originating from the same web site.

While GWT's HTTP client and RPC call can only fetch data from the same site where your application was loaded, you can get data from another server if it returns json in the right format. You must be interacting with a JSON service that can invoke user defined callback functions with the JSON data as argument.

Second, see How to Fetch JSON DATA

Upvotes: 2

Related Questions