This topic is about calling SharePoint web service using jQuery and JavaScript to read the data from lists.
Here we are using lists.asmx web service in the script to read the list data
Script:
$(document).ready(function () {
callWS();
}
});
function callWS() {
var soapEnv =
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
<soapenv:Body> \
<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
<listName>ListName</listName> \
<viewFields> \
<ViewFields> \
<FieldRef Name='Title' /> \
</ViewFields> \
</viewFields> \
</GetListItems> \
</soapenv:Body> \
</soapenv:Envelope>";
$.ajax({
url: "/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
contentType: "text/xml; charset=\"utf-8\""
});
}
function processResult(xData, status) {
$(xData.responseXML).find("z\\:row").each(function () {
var liHtml = "<li>" + $(this).attr("ows_Title") + "</li>";
$("#PlaceHolderId").append(liHtml);
});
}
Here we are using lists.asmx web service in the script to read the list data
Script:
$(document).ready(function () {
callWS();
}
});
function callWS() {
var soapEnv =
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
<soapenv:Body> \
<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
<listName>ListName</listName> \
<viewFields> \
<ViewFields> \
<FieldRef Name='Title' /> \
</ViewFields> \
</viewFields> \
</GetListItems> \
</soapenv:Body> \
</soapenv:Envelope>";
$.ajax({
url: "/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
contentType: "text/xml; charset=\"utf-8\""
});
}
function processResult(xData, status) {
$(xData.responseXML).find("z\\:row").each(function () {
var liHtml = "<li>" + $(this).attr("ows_Title") + "</li>";
$("#PlaceHolderId").append(liHtml);
});
}
No comments:
Post a Comment