Jquery – Sharepoint getlistitems not returning list items

jquerysharepointsharepoint-2010

I'm a bit new to spservices, and I hope I'm not asking a question that's already been answered. I have checked and have not been able to find another question that addressed the same issue as this. I'm using GetListItems to retrieve url's and titles stored in a list. 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 I go 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

Best Answer

It looks like you need to access the root site. If, for some reason, you simply can't use ECMAScript

clientContext = new SP.ClientContext();
var oWebsite = clientContext.get_site().get_rootWeb();  //this is the web object
var url = clientContext.get_site().Url; //this is the root url
var listServiceUrl = url + "/_vti_bin/lists.asmx";

You could always use location.host + "/_vti_bin/lists.asmx" if that's safe in your current setup.