【发布时间】:2012-03-06 14:38:25
【问题描述】:
我有一个来自 Ajax REST 调用的 XML 响应。与下面的类似。
<eventBlock>
<event eventId="641">
<processId>myprocess</processId>
<batchId>15581</batchId>
<user>Ajay</user>
<participant>XYZ</participant>
<activity>Jogging</activity>
<note>Athletic</note>
<createdOn>2011-11-22 00:00:00.0</createdOn>
<createdBy>User5</createdBy>
</event>
</eventBlock>
我的 HTML:
<form class="searchform" id="searchform" action="javascript: submitForm();">
.....
</form>
<div id="UI">
<table id="events" class="display">
<thead>
<tr>
<th>eventId</th>
<th>processId</th>
<th>batchId</th>
<th>user</th>
<th>participant</th>
<th>activity</th>
<th>note</th>
<th>createdOn</th>
<th>createdBy</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
Javascript:
<script type="text/javascript">
var thisTable;
thisTable = $("#events").dataTable(
{
"sPaginationType": "full_numbers",
"bJQueryUI": true
}
);
function addToTable(response){
var $events = $(response).find("event");
$events.each(function(index, event){
var $event = $(event),
addData = [];
addData.push($event.attr("eventId"));
addData.push($event.children("processId").text());
addData.push($event.children("batchId").text());
addData.push($event.children("user").text());
addData.push($event.children("participant").text());
addData.push($event.children("activity").text());
addData.push($event.children("note").text());
addData.push($event.children("createdOn").text());
addData.push($event.children("createdBy").text());
thisTable.fnAddData(addData);
});
}
function submitForm() {
$.ajax({
url:'../../data.xml',
data:{
batchId:1234,
processId:afsfafgg
},
type:"GET",
success:addToTable
});
return false;
}
</script>
当我点击提交时。我在萤火虫上得到以下错误。有人可以帮我解决这个问题吗?
o设置为空 [中断此错误]
var iRow = oSettings.aoData.length;
提前致谢!
【问题讨论】:
-
你确实知道jQuery.parseXML(),对吧?
-
@FlorianMargaine 是的,我知道这一点。但是如何使它与数据表插件一起使用?有什么建议吗?
-
This - 我正在处理 JSON 响应。对处理 XML 响应感到好奇。用数据表尝试了 fnServerData。
标签: jquery datatables