In this blog we are using ECMA + Jquery For Quering Sharepoint 2010 List and then get result with the help of Jquery Like Foreach and then assign to respective field in page
Declare one variable in which we can store our query
var soapEnv =
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
<soapenv:Body> \
<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
<listName>New Messages</listName> \
<query><Query><Where><Eq><FieldRef Name='ID'/><Value Type='Counter'>" + ValueID + "</Value></Eq></Where></Query></query> \
<viewFields> \
<ViewFields> \
<FieldRef Name='Title' /> \
<FieldRef Name='Description' /> \
<FieldRef Name='Address' /> \
<FieldRef Name='Name' /> \
</ViewFields> \
</viewFields> \
</GetListItems> \
</soapenv:Body> \
</soapenv:Envelope>";
Now here with the help of Jquery Ajax we can query List and give our Query
$.ajax({
url: getServerUrl() + "/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
contentType: "text/xml; charset=\"utf-8\""
});
Now you are ready to get data so with the help of Jquery get Value one by one
function processResult(xData, status) {
// following thing will loop foreach Item
$(xData.responseXML).find("z\\:row").each(function () {
//taking value of field Title,Description,Address,Name
var header = $(this).attr("Title");
var description = $(this).attr("Description");
var from = $(this).attr("Address");
var category = $(this).attr("Name");
//you are ready to assign retreved data in page
});
No comments:
Post a Comment