I try to iterate through an array and show the results in a HTML table. The Data is coming from a webservice.
My JavaScript function:
function loadDate() {
var PanelID = document.getElementById('PanelID').value;
alert(PanelID);
$.ajax({
type: "POST",
url: "../../WebService/QRCode.asmx/getDatetime",
data: "{ 'PanelID': '" + PanelID + "' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
cache: true,
success: function(data) {
var table = document.createElement('table');
var str = '<table>';
str += '<tr><th>Von</th><th>Bis</th><th>Thema</th></tr>';
for(var i = 0; i < data.d.length; i++) {
str += '<tr><td>' + data.d[i].Von + '</td><td>' + data.d[i].Bis + '</td><td>' + data.d[i].Thema + '</td></tr>';
}
str += '</table>';
return str;
var existingDiv = document.getElementById('DataTable');
existingDiv.innerHTML = loadDate(data);
},
error: function(x, e) {
alert("The call to the server side failed. " + x.responseText);
}
});
}
HTML Part
<body>
<h1>
Check-In und Check-Out von Besprechungen</h1>
<form id="form1" runat="server">
<div id = "DataTable"> </div>
<p>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
Raumname:
<br />
<asp:TextBox type="text" name="Panels" ID="PanelID" value="" runat="server"></asp:TextBox>
<br />
<br />
<asp:TextBox type="text" ID="Table" mode="multiline" runat="server" Coloumns="100" Rows="200"
Height="230px" Width="405px"></asp:TextBox>
<br />
<br />
<asp:Button ID="button" runat="server" Text="Check-In" Width="99px" OnClientClick="return loadDate();" />
<asp:Button ID="button1" runat="server" Text="Check_Out" Width="99px" />
</p>
</form>
</body>
The Problem is that something is not working in my code. If I do it with the above code I can't display the values.
I think it has something to do wit the for clause, because
f i change the FOR clause for example:
for(var i = 0; i < data.d.length; i++) {
var VonDatum = data.d[i].Von;
$("#Table").val(VonDatum);
}
so I can display the Von value in a textbox. But if I do it like that the FOR clause is displaying only one value, but there are more than 30 values in the array.
My JSON-Data looks like:
{"d":[{"Von":"18.05.2012 00:00:00","Bis":"18.06.2012 00:00:00","Thema":"Raum ist gesperrt","PanelIDs":"FAT-1"}]}