我有一个下拉列表,im试图将一个值传递给datatable函数,值传递给该函数,但jquery数据表未初始化。但出现错误提示-
“ DataTables警告:表ID = example1-无法重新初始化 数据表。有关此错误的更多信息
html
<select name="navyOp" onchange="getApi(this.value);">
<option selected="selected">Select a tank</option>
<option value="32F"> top</option>
<option value="330">bottom</option>
</select>
javascript
getApi("032F");
function getApi(deviceid) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var dataSet = JSON.parse(xhttp.responseText);//deserialization
//start jquery code
$(document).ready(function () {
$('#example1').DataTable({
data: dataSet,
columns: [
{ data: "port", title: "port" },
{ data: "rssi", title: "rssi" }
]
});
});
//end jquery code
}
};
xhttp.open("GET", url", true);
xhttp.setRequestHeader("Authorization", "BASIC avv==");
xhttp.send();
}