Tuesday, 17 April 2012

SharePoint: Call SP web service using jQuery and JavaScript

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);
    });

}

No comments:

Post a Comment

SharePoint 2013: Video file URL from Asset Library

When you are working with Asset library in SharePoint 2013. It is very important to note that how video files are stored and managed in tha...