Get List Items using Jquery in sharepoint


Today I struggled a lot to find the solution to retrieve items from a list in sharepoint using jquery. Finally got solution.

I have one List called City. It contains following fields.


Now I want to retrieve items in this list into home page by using content editor webpart by using jquery. For this following are the steps.

1. First link the jquery library and spservices library to your script file.

2. Prepare a query based on the lists.asmx service for GetListItems function to get the data as per your requirement.

3. Call the ajax function. Following is the entire code.

<script type="text/javascript" src="_layouts/jquery-1.8.2.js"></script>
<script type="text/javascript" src="_layouts/jquery.SPServices-0.7.1a.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        var soapEnv = "<soapenv:Envelope xmlns:soapenv=''> \
                <soapenv:Body> \
                     <GetListItems xmlns=''> \
                        <listName>City</listName> \
                        <viewFields> \
                            <ViewFields> \
                               <FieldRef Name='Title' /> \
                           </ViewFields> \
                        </viewFields> \
                    </GetListItems> \
                </soapenv:Body> \
            url: "http://sp2010:8080/personal/Inclusions/_vti_bin/lists.asmx",
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            complete: processResult,
            error : callError,
            contentType: "text/xml; charset=\"utf-8\""
    function processResult(xData, status) {
        $(xData.responseXML).find("z\\:row").each(function() {
            var liHtml = "<li><a href='#'>" + $(this).attr("ows_Title") + "</a></li>";
        });   }
    function callError(jqXHR, textStatus, errorThrown){   alert(errorThrown); }

    <marquee direction='up' behavior='scroll' style="height:100px" onmouseover= "this.stop();" onmouseout="this.start();"><ul id="tasksUL"/></marquee>

4. Now upload this .js file into shared documents or any other documents list.


5. Now link that .js file into content editor webpart as follows.


6. Now click on ok. Now you can see in the content editor webpart the list items are scrolling(marquee effect). The useful area of this .js file is, to show the any upcoming events in home page. We dont need to go for visual studio to develop this. Just we should aware of  javascript and jquery.


Published by


Nothing to say.. lot to hear

2 thoughts on “Get List Items using Jquery in sharepoint”

  1. you are awesome!! This is the only post which worked without any tweaking…. I have followed so may posts on jquery and SpServices.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s