jquery ui のタブがいくつかあります。各リンクは json 応答を受信する必要がありますが、機能させることができません。これはアクティブなものです:
<li class="ui-state-default ui-corner-top ui-tabs-active ui-state-active" role="tab" tabindex="0" aria-controls="ui-tabs-1" aria-labelledby="ui-id-1" aria-selected="true">
<a href="/comments.json" class="ui-tabs-anchor" role="presentation" tabindex="-1" id="ui-id-1">comments</a>
</li>
応答は次のとおりです。
[{"created_at":"2013-07-12T22:51:46Z","id":8,"programa_id":88,"sent_at":"2013-07-12T22:51:46Z","texto":"testing","updated_at":"2013-07-12T22:51:46Z","user_id":null}]
私はいくつかのことを試しましたが、最善のアプローチは次のとおりです。
$( "#tab_messages" ).tabs({
heightStyle: "fill",
beforeLoad: function( event, ui ) {
ui.ajaxSettings.dataType = "json";
ui.ajaxSettings.dataFilter = function(data) {
var jsonData = $.parseJSON(data);
alert(jsonData[0].texto);
return jsonData[1].texto;
};
ui.jqXHR.error(function() {
ui.panel.html(
"Couldn't load this tab. We'll try to fix this as soon as possible. " +
"If this wouldn't be a demo." );
});
}});
});
パネルがロードされません (jqXHR.error が表示されます) が、jsonData[1].texto を返すと動作します。