【问题标题】:datatable plugin - show and hide more information about a row数据表插件 - 显示和隐藏有关行的更多信息
【发布时间】:2011-05-01 09:38:34
【问题描述】:
数据表插件 - 显示和隐藏有关行问题的更多信息:
我想通过 fnFormatDetails 函数中的 ajax 获取更多信息。但我不知道怎么做。我尝试将 $.ajax 放在 fnFormatDetails 函数中,但将输出传递给 fnOpen 函数似乎有延迟渲染新添加的行,所以新行是用空(未定义)值而不是真实信息创建的。
我该怎么做?
谢谢。
【问题讨论】:
标签:
jquery-plugins
jquery
datatables
【解决方案1】:
AJAX 中的“A”代表“异步”。当您进行$.ajax 调用时,该函数会在服务器响应之前返回,因此是“异步的”。 $.ajax() 函数有一个接收服务器响应的成功回调,该回调必须完成处理服务器响应和更新页面的所有工作:
$.ajax({
url: '/where/ever',
data: data_for_the_url,
success: function(data, textStatus, jqXHR) {
/*
* This is where you use `data` to update the page.
* $.ajax will call this function when the server
* has successfully responded.
*/
}
});
/*
* When you get here, the server still hasn't responded so you can't
* update your page yet.
*/
所以,将所有页面更新逻辑放在success 回调函数中。