Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm a bit new to spservices, and I hope I'm not asking a question that's already been answered. I've checked and haven't been able to find one like it. I'm using GetListItems to retrieve url's and titles stored in a list. No problems understanding the logic, and it should work. Right now I'm retrieving items and just displaying them in a temporary table.

It works perfectly in a little html page that I've created that references the js files, jquery, etc.

But,

When I set a Content Editor Web Part to point to the html file (using the Content Link), the javascript doesn't work, (or something), and the items aren't displayed. I found out where exactly it stopped working:

 $().SPServices({
                operation: method,
                async: false,
                listName: list,
                CAMLViewFields: fieldsToRead,
                  CAMLQuery: query,
                    completefunc: function (xData, Status) {
         alert("When it's in the Content Editor Web Part, this gets called");
                        $(xData.responseXML).SPFilterNode("z:row").each(function() {
         alert("but this does not");
                            var hyperlink = ($(this).attr("ows_Hyperlink")).split(",");
                            var url = hyperlink[0];
                            var description = hyperlink[1];


                            AddRowToTable(url,description);

                        });                
                    }
        });

As I said before, this code works perfectly when going to the physical address of the html page. It grabs the list items and displays the correct things. The problems occur when I reference, through the Content Link, the html page in the Content Editor Web Part. If anyone has insight on this, it would be most welcome. Thanks, AA

share|improve this question
    
If the first alert is displayed, but the second isn't, then it suggest that the query work, but doesn't return any rows. What's in xData.responseXML? –  Per Jakobsen Jul 24 '12 at 16:20
    
I put this in: alert(xData.responseXML); and it gives me this: [object XMLDocument] –  arthur.e.anderson Jul 24 '12 at 16:52
    
Try alert(xData.response.XML.xml); or console.log(xData.response.XML.xml); and use Developer Tools (F12) –  Per Jakobsen Jul 24 '12 at 17:06
    
It says that the list doesn't exist. I don't understand. Does it being in a CEWP mess with where it looks? –  arthur.e.anderson Jul 24 '12 at 17:43
    
Not if it's on the same Site as where you tried with html page. Have you checked your variables (list, query, ...)? –  Per Jakobsen Jul 24 '12 at 17:50
show 1 more comment

1 Answer 1

up vote 2 down vote accepted

In the comments to the question you mention that you found that the page is in a subsite and the list you want is at the root site.

To change where it looks for the list you can specify a webURL property:

 $().SPServices({ 
            operation: method, 
            async: false, 
            webURL: 'http://sharepoint/',
            listName: list, 
            CAMLViewFields: fieldsToRead, 
              CAMLQuery: query, 
                completefunc: function (xData, Status) { 
                    $(xData.responseXML).SPFilterNode("z:row").each(function() { 
                        var hyperlink = ($(this).attr("ows_Hyperlink")).split(","); 
                        var url = hyperlink[0]; 
                        var description = hyperlink[1]; 


                        AddRowToTable(url,description); 

                    });                 
                } 
    }); 
share|improve this answer
    
Thank you sir, this did it. –  arthur.e.anderson Jul 24 '12 at 18:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.