当我将值传递给我的函数时,数据表正确显示,但是当我执行搜索时表是空的。
function Domain(did2) {
did1 = did2; //localStorage.getItem("did2");
var url = 'myurl?id=' + did1;
$.ajax(url, { async: false }).then(function success(data) {
data = JSON.parse(data);
var tab = $("#TableDomain > tbody");
tab.empty();
$.each(data, function (index, value) {
var row = $("<tr><td>" + value.Id + "</td><td>" + value.Name + "</td></tr>");
$("#TableDomain").append(row);
});
});
}
<script>
$(function(){
$("#TableDomain").dataTable();
});
</script>
答案 0 :(得分:0)
请将您的代码更改为:
did1 = did2; //localStorage.getItem("did2");
var url = 'myurl?id=' + did1;
$.ajax({
url:url,
async: false,
success:function success(data) {
data = JSON.parse(data);
var tab = $("#TableDomain > tbody");
tab.empty();
$.each(data, function (index, value) {
var row = $("<tr><td>" + value.Id + "</td><td>" + value.Name + "</td></tr>");
$("#TableDomain").append(row);
});
}
});