2

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

6
  • 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? Commented Jul 24, 2012 at 16:20
  • I put this in: alert(xData.responseXML); and it gives me this: [object XMLDocument] Commented Jul 24, 2012 at 16:52
  • Try alert(xData.response.XML.xml); or console.log(xData.response.XML.xml); and use Developer Tools (F12) Commented Jul 24, 2012 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? Commented Jul 24, 2012 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, ...)? Commented Jul 24, 2012 at 17:50

1 Answer 1

2

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); }); } }); 
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.