I'm trying to load in a SharePoint list to a Unordered List so I can create a simple search function (the Sharepoint Search is just horrible). The code I have borrowed and adapted is below:
$(document).ready(function() {
var soapEnv =
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
<soapenv:Body> \
<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
<listName>Metric_Audit</listName> \
<viewFields> \
<ViewFields> \
<FieldRef Name='ReportName' /> \
<FieldRef Name='Metric Name' /> \
</ViewFields> \
</viewFields> \
</GetListItems> \
</soapenv:Body> \
</soapenv:Envelope>";
$.ajax({
url: "http://teamspace.intranet.group/sites/CSI/ID/DB/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: Result,
contentType: "text/xml; charset=\"utf-8\""
});
});
function Result(xData, status) {
$(xData.responseXML).find("z\\:row").each(function() {
var liHtml = "<li>" + $(this).attr("ows_ReportName") + "</li>";
$("#MetricsUL").append(liHtml);
});
}
});
<ul id="MetricsUL"/>
It populates the list as it should but all the items have the name 'undefined'. I have tried removing spaces etc. to no avail and when I change the list to the 'tasks' list it works just fine.
Been staring at this for AGES. Any tips you can suggest would be really appreciated! I'm sure it's something small that I just can't work out!
Thanks!