我有一些带有 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,它可以工作。