I want to retrieve my database values and insert them into a table.
I am trying to iterate i
onto an array.
However, it returns undefined and there is no output. Why is this so?
Could it be an issue with the script or the body tag?
Script
function getitemdetails() {
var xmlhttp = new XMLHttpRequest();
var url = serverURL() + "/mycasefeed.php";
url += "?Case_ID=" + decodeURIComponent(getUrlVars()["Case_ID"]);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
getitemResult(xmlhttp.responseText);
};
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
function getitemResult(response) {
var arr = JSON.parse(response);
var i;
for(i = 0; i < arr.length; i++) {
$("#mycase").append("<tr><td>" + arr[i].CaseDes +
arr[i].Case_Pic +
"<br>" + arr[i].categoryname +
"<br>" + arr[i].Caselat +
"<br>" + arr[i].Caselong +
"<br>" + arr[i].CaseTime +
"<br>" + arr[i].details + "</td></tr>");
}
$("#mycaseresult").table("refresh");
}
getitemdetails();
Body
<div id="SearchResult" class="ui-content">
<table data-role="table" data-mode="reflow" class="ui-responsive" id="mycaseresult">
<thead>
<tr>
*insert values here*
</tr>
</thead>
<tbody id="mycase">
</tbody>
</table>
</div>