我不知道为什么,但footable文档只显示了一种从文件中获取数据的方法,而不是从why服务中获取数据,所以我尝试了各种组合,将数据以json格式返回到footable实例中,但没有成功。他们的示例显示了以下内容:
$('.table').footable({
"rows": $.get('rows.json')
});(假设已经定义了列),这是可行的。但是,在我的ajax查询中,我尝试
$('.table').footable({
"rows": data.d
});并且没有发生错误,数据的格式是正确的(使用在线JSON模式检查器进行了验证),但是什么也没有发生(控制台中没有错误)。
我彻底测试了ajax查询(可以工作,我甚至可以解析返回的data.d ),所以我不知道如何继续。
$.ajax({
type: "POST",
url: "/Search.asmx/GetListingsByPageSort",
data: '{"sp":' + JSON.stringify(sp) + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
$('.table').footable({
"rows": data.d
});
},
error: function (xhr, status) {
alert("fail: " + status);
}
});HTML是
<table class="table" data-paging="true">
<thead>
<tr>
<th class="hdrcolVdr" data-class="expand" data-type="html" data-name="vendor">Vendor </th>
<th class="hdrcolMan" data-breakpoints="xs sm" data-type="html" data-name="manufacturer">Manufacturer </th>
<th class="hdrcolProd" data-breakpoints="xs sm md" data-type="html" data-name="product_name">Product </th>
<th class="hdrcolPrice" data-breakpoints="xs" data-type="html" data-name="price">Price </th>
<th class="hdrcolI" data-breakpoints="xs sm" data-type="html">Info </th>
</tr>
</thead>
</table>被难住了。
发布于 2017-03-29 20:10:15
我发现(经过艰苦的工作)问题来自于GET/POST响应的异步方式。在我的代码中,这是可行的:
rows : $.get('js/rw1.json')
但这并不管用:
rows : $.get("rest.php")
即使它们都给出了相同的值(可以看到跟踪网络流量)。
我已经解决了在同步模式下强制jQuery等待GET响应的问题。可能不是一个很好的解决方案,但它是有效的。这是我的代码:
rows : ajaxRows();
其中,ajaxRows是:
function ajaxRows(){
var retu;
jQuery.ajaxSetup({async:false});
retu = $.get("rest.php");
jQuery.ajaxSetup({async:true});
return retu;
}在你的代码中,也许你应该添加到$.ajax参数中:
async:false
HTH
马可
https://stackoverflow.com/questions/41668194
复制相似问题