1

我是GWT的新手,abc.com我在哪些 RPC 调用用于从其服务器获取数据。任何帮助将不胜感激。xyz.comxyz.com?id=1jsonjsonabc.comRPC

编辑

我正在尝试在此StockWatcher 教程中实现这一点

我把我的代码稍微改了一下

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

 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));
                }
            });


        }

之前当我通过RequestBuilder它请求我的 url 时给了我一个异常Couldn't retrieve JSON,但现在JSON已获取并且状态代码为 200,正如我在其中看到的那样,firebug但它没有在表上更新。请帮助我解决这个问题。

4

1 回答 1

2

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

于 2012-08-13T22:09:21.157 回答