hagino3000's blog

平成アーカイブス (更新停止)

jQuery用JSON RPCプラグイン書いた

gitとgithubの使い方を覚えるために、手元のコードをgithubにアップしてみた。jQuery.getJSONっぽく使える。

使い方

$.jsonRpc(url, data[, callbackFunc]);

サンプル

// RPC call with named parameters
$.jsonRpc('/rpc', {
  method : 'createUser',
  params : {name : 'John Smith', userId : '1000'}
}, function(response, status) {
  // callback
  console.info(status);
  if (response.error) {
    console.dir(response.error);
  } else {
    doSomething(response.result);
  }
});

// A Notification 
$.jsonRpc('/rpc', {
  method : 'notify',
  params : {action : 'logout', userId : '1000'}
});

課題

ここ<http://groups.google.com/group/json-rpc/web/json-rpc-2-0>の仕様を見て実装したんだけど、サーバーがエラーの時もこんな感じ

{
  "jsonrpc" : "2.0",
  "result" : null,
  "error" : {
    "code" : XXXX, 
    "message" : "Temporary Service Unavailable"
  },
  "id" : 1
}

JSONが返ってくる事を期待するわけですが、本当にJSONで返ってくるの?? という所。HTMLが返ってきたらどうしよう、みたいな。GAEが落ちた時どうなるかも気になる。