one of my ASP.Net project. Was just cusrious to know how this can be used to call SharePoint webservices. With jQuery you can call SharePoint webservice with couple of lines of code. Also jQuery makes XML utilization very easy. The sample code below shows how to traverse XML nodes which is returned by GetListItems method of Lists.asmx webservice. The XML returned by GetListItems method uses XML namespace, which cuases some problem while using jQuery. The technique used in sample below works fine on IE 6, i have not tried this on other browsers.
In order to use jQuery APIs inside ShaerPoint page, you need to add the script file reference to your page.
Following steps show you how to reference this library:
1. Copy the jQuery javascript file to 12\Tempalte\Layout\1033 folder
2. Edit your master page and add following script file reference
<script type="text/javascript" language="javascript" src="/_layouts/1033/jquery-1.3.2.min.js"></script>
Following sample code reads document name from sharepoint document library (Shared Documents):
<script type="text/javascript>
$(document).ready(function() {
var xmlData ="<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/
2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001
/XMLSchema'><soap:Body><GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'><listName>Shared Documents</listName><query><Query
xmlns=''><OrderBy><FieldRef Name='Title' /></OrderBy></Query></query><viewFields><
ViewFields xmlns='' /></viewFields><queryOptions><QueryOptions xmlns='' /></queryOptions></GetListItems></soap:Body></soap:Envelope>";
$.ajax({
url: "/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: xmlData,
complete:SuccessFunc,
error: ErrorFunc,
contentType: "text/xml; charset=\"utf-8\""
});
});
function SuccessFunc(result) {
//xml node with namespace need to be handled differently for jQuery
$(result.responseXML).find("z\\:row").each(function() {
alert($(this).attr("ows_BaseName"));
});
}
function ErrorFunc(result) {
alert(result.responseText);
}
</script>
