2
IMO我按照这里的教程Googles x-siteGWT JSON跨站点请求失败
/**
* Make call to remote server.
*/
public native static void getJson(int requestId, String url,
StockWatcher handler) /*-{
var callback = "callback" + requestId;
// [1] Create a script element.
var script = document.createElement("script");
script.setAttribute("src", url+callback);
script.setAttribute("type", "text/javascript");
// [2] Define the callback function on the window object.
window[callback] = function(jsonObj) {
// [3]
[email protected]::handleJsonResponse(Lcom/google/gwt/core/client/JavaScriptObject;)(jsonObj);
window[callback + "done"] = true;
}
// [4] JSON download has 1-second timeout.
setTimeout(function() {
if (!window[callback + "done"]) {
[email protected]::handleJsonResponse(Lcom/google/gwt/core/client/JavaScriptObject;)(null);
}
// [5] Cleanup. Remove script and callback elements.
document.body.removeChild(script);
delete window[callback];
delete window[callback + "done"];
}, 1000);
// [6] Attach the script element to the document body.
document.body.appendChild(script);
}-*/;
但它一直没有我..所有其他methos也被写入一切正常..我只是可以理解为什么它告诉我每一个“无法检索JSON”时间(这是说,当处理程序的输入为null)
顺便说一句我说的是在谷歌网站
我试过了。 它工作的静态文件,但在动态json文件的情况下,它总是失败。 有什么想法? – user365314 2010-08-09 07:15:36
您*负责在服务器端生成JSON文件吗?那么也许这是一个错误:D(没有进攻;))无论哪种方式,尝试通过浏览器或wget下载动态和静态文件,并比较和验证它们:http://www.jsonlint.com/是一个很棒的JSON验证器。另外:“它总是失败” - 你能更具体地说明它是如何“失败”的? :d – 2010-08-09 09:43:47