Navigate Up
Sign In
Supporters of Developer
Web

Accessing List Items using jQuery and SharePoint Web Services

Item is currently unrated. Press SHIFT+ENTER to rate this item.1 star selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+ESCAPE to leave rating submit mode.2 stars selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.3 stars selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.4 stars selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.5 stars selected. Press SHIFT+ENTER to submit. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.
Accessing List Items using jQuery and SharePoint Web Services

Source: Jan Tielens

The code below can be used to access list items in a SharePoint list leveraging jQuery and SharePoint Web Services.

<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>

<script type="text/javascript">
    $(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>Tasks</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>";
            $("#tasksUL").append(liHtml);
        });
    }
</script>

<ul id="tasksUL"/> 
Categories:
No categories were selected

Comments

Walter Parrish

Re: Accessing List Items using jQuery and SharePoint Web Services

OK... I see the reference to _vti_bin/lists.asmx but I would have expected a reference to an operation such as GetListItems to actually access the title.

When I paste the code above into a Content Editor web part nothing happens...

Am I totally "off base"?

Posted 24-Aug-2009 by Walter Parrish

Re: Accessing List Items using jQuery and SharePoint Web Services

Hi Walter,

I did also try this code and nothing happened. Then after some checkups I found what worked for my case. The problem was with the reference to the _vti_bin/lists.asmx beeing relatively and the page beeing in Pages-library (which is what should be). For some kind of reason, when clicking on "Service Description" on following url, it' returns "XML Parsing Error: no element found (FF says so, IE doesn't even render the page).

http://localhost/Pages/_vti_bin/lists.asmx?WSDL

But when I modify URL with following, everything works correctly, and then my JQuery do populate ul.

The new url is following:

http://localhost/_vti_bin/lists.asmx?WSDL

Could this be a bug in SharePoint!? Maybe, I don't know. 

Posted 24-Aug-2009 by

Re: Accessing List Items using jQuery and SharePoint Web Services

Very useful, I'm using since some times now with great results. One question though: is it possible when querying a list to get the url of the file attached to the list item? As far as I saw the query just returns the following elements regarding an attachment:

ows_Attachments='1'
ows_FileRef='[item ID];#[siteName]/Lists/[listName]/[item ID]_.000'

if someone already had the problem I would be glad to have any information about it!

Posted 23-Sep-2009 by
Marc D Anderson

Re: Accessing List Items using jQuery and SharePoint Web Services

There are multiple Web Services available, and you can combine calls to them to do more useful stuff.  Check out our [relatively] new jQuery Library for SharePoint Web Services.  This jQuery plugin "wraps" the SharePoint Web Services so that you can call them as easily as (for the above example):

$().SPServices({
  operation: "GetListItems",
  listName: "Tasks",
  CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
  completefunc: function (xData, Status) {
    $(xData.responseXML).find("z:row").each(function() {
      var liHtml = "" + $(this).attr("ows_Title") +"";
      $("#tasksUL").append(liHtml);
    });
  }
});

 M.

Posted 24-Sep-2009 by Marc D Anderson
Shawn

Re: jQuery Library for SP Web Services

Hey Marc, I can't seem to get that example you posted to work, I'm using the latest version of jQuery for SP (I've actually been using it for the comparably simpler task of changing form field strings until now). I tried looking at the jQuery Library API, but couldn't find info on the operation "GetListItems". I was able to use the code at the top of this page, but your example seems to be much more concise and I'm all for intelligent componentalization.

Posted 24-Jan-2011 by Shawn
Gaurav

getting list items in sharepoint 2010 through web services

Hi i tried using this script with sharepoint 2010 but it didn't work
 
and i am also not getting any error , i also used latest version but still it didn'yt work
 
any help is appreiciated
 
Garav 

Posted 25-Aug-2011 by Gaurav
Kanure

Kanure

Nice post,
I have a dashboard section on my home page of the site, which brings data from a sensitive
list. Currently users who dont have access to the list cant see anything in the Dashboard section.
Is there any method by which i can use a default system account and display this data to all the users, without giving them direct access to the list.
Can login id and passed be sent in your method for remote authentication.
Please suggest.

Posted 08-Jun-2012 by Kanure
S J

Same thing by the same owner

http://weblogs.asp.net/jan/archive/2009/05/06/querying-sharepoint-list-items-using-jquery.aspx

Posted 22-Aug-2012 by S J

Notify me of comments to this article

E-mail:
   

Add Comment

Title:

 
Comment:
Email:

   


Name:

 
Url: