This project has moved and is read-only. For the latest updates, please go here.

Display data from 2 lists in one page

Nov 14, 2011 at 11:31 AM



I am new to jquery so go easy on me!  I need to display columns from 2 different lists on different web parts.


I can connect to one list with the following code...


<script type="text/javascript" src="/resources/Javascript/jquery.js"></script>

<script type="text/javascript">
    $(document).ready(function() {
        var soapEnv =
            "<soapenv:Envelope xmlns:soapenv=''> \
                <soapenv:Body> \
                     <GetListItems xmlns=''> \
                        <listName>Tasks</listName> \
                        <viewFields> \
                            <ViewFields> \
                               <FieldRef Name='Title' /> \
                           </ViewFields> \
                        </viewFields> \
                    </GetListItems> \
                </soapenv:Body> \

            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>";

<ul id="tasksUL"/>


My problem is: how do I connect to a second list on a different web part, but on the same page?  I only seem to be able to copy over whatever is displayed on the above coding.


Many thanks


Nov 14, 2011 at 11:34 AM

You don't seem to be using SPServices, but that doesn't really matter.

Your issue is probably that you are referencing the jQuery library twice, if you are copying this code. You should only reference it once per page.

Nov 14, 2011 at 11:41 AM

Thanks for the quick response M.


I have stripped the reference to jquery and simply replicated the SOAP:Env, the reference to the web services and then just assigned a different div name whilst doing the styling under processResult method, but still no luck!




Nov 15, 2011 at 10:48 AM


it's hard to say. I think you'll need to do some debugging. Since you're asking this question here on the SPServices site, you might consider using SPservices to make things easier.


Nov 29, 2011 at 7:42 PM


You will need to create the 2nd UL with a different UL ID.

So, the 1st list display can use the <ul id="tasksUL"/>, but the 2nd list display needs to be something like <ul id="tasksUL2"/>

Remember, to change all occurences of tasksUL in your 2nd web part to the new id name.

Good luck and let us know,