|
AppData
It is possible to save application data. Data items can be specified.
jQuery.ajax, jQuery.get, jQuery.getData, jQuery.post, jQuery.postData en, ja opensocial-0.8 is required for datatype="data" in jQuery.ajax <Require feature="opensocial-0.8" /> Save DataIt is possible to save VIEWER data using jQuery.ajax $.ajax({
type: 'post',
url: '/appdata/@viewer/@self',
data: {
comment: { text: 'Say Hello!', lastModified: new Date().getTime() },
feeling: 'well',
footprint: true
},
dataType: 'data',
success: function() {},
error: function(xhr, status, e) {
console.error(xhr, status, e);
}
});This can also be done using jQuery.post $.post('/appdata/@viewer/@self', {
comment: { text: 'Say Hello!', lastModified: new Date().getTime() },
feeling: 'well',
footprint: true
}, function() {}, 'data');The same can be done using jQuery.postData $.postData('/appdata/@viewer/@self', {
comment: { text: 'Say Hello!', lastModified: new Date().getTime() },
feeling: 'well',
footprint: true
}, function() {});Obtain DataVIEWER data can be obtained by using jQuery.ajax $.ajax({
url: '/appdata/@viewer/@self',
data: {},
dataType: 'data',
success: function(data) {
$.each(data, function(userId, data) {
console.info(data.comment.text);
console.info(data.comment.lastModified);
console.info(data.feeling);
console.info(data.footprint);
});
},
error: function(xhr, status, e) {
console.error(xhr, status, e);
}
});This can also be done using jQuery.get $.get('/appdata/@viewer/@self', {}, function(data) {}, 'data');The same can be done using jQuery.getData $.getData('/appdata/@viewer/@self', {}, function(data) {});OWNER data can be obtained by using jQuery.ajax $.ajax({
url: '/appdata/@owner/@self',
data: {},
dataType: 'data',
success: function(data) {
$.each(data, function(userId, data) {
console.info(data.comment.text);
console.info(data.comment.lastModified);
console.info(data.feeling);
console.info(data.footprint);
});
},
error: function(xhr, status, e) {
console.error(xhr, status, e);
}
});This can also be done using jQuery.get $.get('/appdata/@owner/@self', {}, function(data) {}, 'data');The same can be done using jQuery.getData $.getData('/appdata/@owner/@self', {}, function(data) {});Obtaining Friends' DatajQuery.ajax can be used to obtain data of a Viewers' friends $.ajax({
url: '/appdata/@viewer/@friends',
data: {},
dataType: 'data',
success: function(data) {
$.each(data, function(userId, data) {
console.info(data.comment.text);
console.info(data.comment.lastModified);
console.info(data.feeling);
console.info(data.footprint);
});
},
error: function(xhr, status, e) {
console.error(xhr, status, e);
}
});This can also be done using jQuery.get $.get('/appdata/@viewer/@friends', {}, function(data) {}, 'data');The same can be done using jQuery.getData $.getData('/appdata/@viewer/@friends', {}, function(data) {});jQuery.ajax can be used to obtain data of an OWNER's friends $.ajax({
url: '/appdata/@owner/@friends',
data: {},
dataType: 'data',
success: function(data) {
$.each(data, function(userId, data) {
console.info(data.comment.text);
console.info(data.comment.lastModified);
console.info(data.feeling);
console.info(data.footprint);
});
},
error: function(xhr, status, e) {
console.error(xhr, status, e);
}
});This can also be done using jQuery.get $.get('/appdata/@owner/@friends', {}, function(data) {}, 'data');jQuery.ajax can be used to obtain data of an OWNER's friends $.getData('/appdata/@owner/@friends', {}, function(data) {});Specify Data ItemsSaved data items can be specified using the fields parameters. Data items are specified by comma-delimiting $.ajax({
type: 'post',
url: '/appdata/@viewer/@self?fields=comment,feeling',
data: {
comment: { text: 'Say Hello!', lastModified: new Date().getTime() },
feeling: 'well',
footprint: true
},
dataType: 'data',
success: function() {},
error: function(xhr, status, e) {
console.error(xhr, status, e);
}
});Obtained data items can be specified using the fields parameters. Data items are specified by comma-delimiting $.ajax({
url: '/appdata/@viewer/@self?fields=comment,feeling',
data: { fields: 'comment,feeling' },
dataType: 'data',
success: function() {
$.each(data, function(userId, data) {
console.info(data.comment.text);
console.info(data.comment.lastModified);
console.info(data.feeling);
});
},
error: function(xhr, status, e) {}
});Furthermore, the fields parameter can also be used to define the URL $.ajax({
url: '/appdata/@viewer/@self?fields=comment,feeling',
data: {},
dataType: 'data',
success: function() {},
error: function(xhr, status, e) {}
});HTML UnescapeData is HTML unescape with jQuery.ajax, jQuery.get, and jQuery.getData |
データを取得する際、jQuery.get、 jQuery.getData などが使えると書かれてありますが、この場合には function がひとつしかありません。このような場合のエラー処理はどうすればいいのでしょうか?
上記の件、opensocial-jquery というよりは、jQuery Ajax のエラーハンドリングの質問になります。
jQuery Ajax の主なエラーハンドリングの方法は、次のとおりです。
(1) jQuery.ajax の error を使う
(2) jQuery.fn.ajaxError を使う http://docs.jquery.com/Ajax/ajaxError#callback
(3) Deferred チェーンの error を使う http://code.google.com/p/opensocial-jquery/wiki/AjaxDeferred
jQuery.get や jQuery.getData はエラーのときコールバックしません。つまり、エラーハンドリングできません。
データを削除するメソッドは今のところありませんか?
> データを削除するメソッドは今のところありませんか?
はい。1.0.4 時点で appdata の delete は実装していません。
jQuery 自体が get と post メソッドしかサポートしてないので、delete メソッドを作り込む(める)か? という技術上の制約があり後回しにしてきました。
appdata の delete を必要とする状況になりましたでしょうか?
>appdata の delete を必要とする状況になりましたでしょうか? 開発中に消したいなという状況はありましたが、必須ではないと思います。 例えば{game_a_score:100}などとあったときにgame_aをいままでプレイしたことあるかどうかを値のあるなしで判定しようとしていたというような感じです。undefinedとかの値を入れれば済む話ですよね。 それにgetとpostのようにそう頻繁に使うものではないので、大丈夫です。ありがとうございました。
状況のご紹介ありがとうございました。もし必要になりましたら対応しますので、そのときになったらリクエストください。