【发布时间】:2011-11-16 05:39:32
【问题描述】:
通过 jquery 对 Tornado Web 服务器的 jsonrpc 2.0 调用会得到一个 “200 OK”http 响应和我的网络嗅探器显示解码 响应包含
{"jsonrpc":"2.0","error":null,"result":3500,"id":"jsonrpc"}
即有效的 jsonrpc 2.0 响应。 3500也是正确的结果, RPC 是一个简单的添加函数。
但是 firebug 不显示响应和 .ajax success 回调 不触发。 .ajax() error 和 complete 回调是 触发但不让我知道问题所在。这里是 触发 ajax() 调用的 index.html。
$(document).ready(function(){
$.ajax({
url: 'http://localhost:8080',
data: JSON.stringify ({jsonrpc:'2.0',method:'add', params:[1400,2100],id:"jsonrpc"} ), // id is needed !!
type:"POST",
dataType:"json",
success: function (result) {
alert("ok");
},
error: function (err,status,thrown) {
alert ("this syntax sucks!! " + " ERROR: " + err + " STATUS: " + status + " " + thrown );
},
complete: function (xhr,status) {
alert('Complete=> showing status as: '+ status);
data = $.parseJSON(xhr.responseText);
alert (data);
}
});
});
【问题讨论】:
-
错误和完成的状态和错误是什么?
-
最初我使用 Firefox“文件打开”加载 index.html(如上所示)。当我浏览localhost:8080 时,我没有这样做,而是让我的 Tornado Web 服务器提供它。这彻底解决了问题。现在成功触发,我得到正确的远程过程调用结果。