ExtJs 4のRESTFul Store exampleをビルドしています。追加または削除リクエストが失敗した場合、RESTサーバーが提供するエラーをスクリプトに表示したいです。私はリクエストの成功状況を取得することができましたが(下記のコードを参照してください)、レスポンスとともに提供されるメッセージにはどのように連絡しますか?ExtJs 4でREST応答メッセージを取得する方法は?
ストア:
var store = Ext.create('Ext.data.Store', {
model: 'Users',
autoLoad: true,
autoSync: true,
proxy: {
type: 'rest',
url: 'test.php',
reader: {
type: 'json',
root: 'data',
model: 'Users'
},
writer: {
type: 'json'
},
afterRequest: function(request, success) {
console.log(success); // either true or false
},
listeners: {
exception: function(proxy, response, options) {
// response contains responseText, which has the message
// but in unparsed Json (see below) - so I think
// there should be a better way to reach it than
// parse it myself
console.log(proxy, response, options);
}
}
}
});
典型的なRESTの応答:
"{"success":false,"data":"","message":"VERBOSE ERROR"}"
はおそらく、私はそれがすべて間違ってやっているので、何かアドバイスは歓迎です。
スーパー!完全に動作します、詳細な説明をありがとう! :-D – Dae
最終的に私はシンプルなAjax APIに賛成してRESTをあきらめました。ここに私の最終的な応答メッセージ処理コードがあります:http://pastie.org/2657317 – Dae
これは素晴らしい説明です...賢者はドキュメントにこれを追加する必要があります! – HDave