GetListItem Working in IE but not others

May 28, 2012 at 4:52 PM

Hi,

Environment - Office 365 for Enterprise.
Requirement - Pull latest blog posts from another site collection Blog Site

Hi,

I have added the script below to a Content Editor web part (pulled from a txt file) which then loads and gives me the latest titles of blog posts in IE.  However it does not work in other browsers that I have tested (firefox, chrome and Safari).  Have I missed something.

Thanks

<script type="text/javascript" src="/siteassets/jquery.SPServices-0.7.1a.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){
$().SPServices({
operation: "GetListItems",
async: false,
webURL: "https://Customer.sharepoint.com/sites/customer/news",
listName: "Posts",
CAMLViewFields: "<ViewFields><FieldRef Name='EncodedAbsUrl' /><FieldRef Name='Title' /></ViewFields>",
CAMLRowLimit:5,
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
var url = $(this).attr("ows_EncodedAbsUrl") + "";
if(($(this).attr("ows_EncodedAbsUrl") + "").match(/000$/))
{
url = url.substring(0, url.lastIndexOf("/", url.length));
url = url + "/Post.aspx?ID=" + $(this).attr("ows_ID");
}
var link = "<a href='" + url + "'>" + $(this).attr("ows_Title") + "</a>";
$("#sitecollectionlink").append(link);
});
}
});
});
</script>

<span id="sitecollectionlink">Latest Blog Article:</span>
Coordinator
May 28, 2012 at 4:58 PM

Alex:

The first thing I would suggest is to switch to a relative URL:

webURL: "/sites/customer/news",

Since the other browsers may be using a different authentication mechanism, you should look at the Net traffic with Firebug (for example) to see what's stopping the data. It's usually the auth stuff that causes problem, not the script itself.

M.

p.s. This hocus pocus isn't really necessary:

var url = $(this).attr("ows_EncodedAbsUrl") + "";

May 28, 2012 at 6:16 PM

No luck I'm afriad - I tried changing the URL and then also trying it with a blog post in the same site collection and it wasn't that either.



<script type="text/javascript" src="/siteassets/jquery.SPServices-0.7.1a.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){
$().SPServices({
operation: "GetListItems",
async: false,
webURL: "sites/wlc/news",
listName: "Posts",
CAMLViewFields: "<ViewFields><FieldRef Name='EncodedAbsUrl' /><FieldRef Name='Title' /></ViewFields>",
CAMLRowLimit:5,
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
var url = $(this).attr("ows_EncodedAbsUrl") + "";
if(($(this).attr("ows_EncodedAbsUrl") + "").match(/000$/))
{
url = url.substring(0, url.lastIndexOf("/", url.length));
url = url + "/Post.aspx?ID=" + $(this).attr("ows_ID");
}
var link = "<p>" + "<a href='" + url + "'>" + $(this).attr("ows_Title") + "</a>" + "</p>";
$("#sitecollectionlink").append(link);
});
}
});
});
</script>

<span id="sitecollectionlink">Test</span>
Coordinator
May 28, 2012 at 6:38 PM

Ok, then the next step is to look at what's coming back from the call to see what the issue is. Right below this line:

completefunc: function (xData, Status) {

add an alert:

alert(xData.responseText);

That will show you what is coming back from the Web Service call, and may give you a hint on the error.

BTW, I note that you don't have the leading / on your webURL.

M.

May 29, 2012 at 7:42 AM

Thanks but that hasnt worked either.  I've placed the alert in the code where you have suggested which runs in IE and I get an alert box but I dont get the alert box in firefox or chrome. 

Any thoughts?

Thanks

A.

<script type="text/javascript" src="/siteassets/jquery.SPServices-0.7.1a.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){
$().SPServices({
operation: "GetListItems",
async: false,
webURL: "/sites/wlc/news",
listName: "Posts",
CAMLViewFields: "<ViewFields><FieldRef Name='EncodedAbsUrl' /><FieldRef Name='Title' /></ViewFields>",
CAMLRowLimit:5,
completefunc: function (xData, Status) {



alert(xData.responseText);


$(xData.responseXML).SPFilterNode("z:row").each(function() {



var url = $(this).attr("ows_EncodedAbsUrl") + "";
if(($(this).attr("ows_EncodedAbsUrl") + "").match(/000$/))
{
url = url.substring(0, url.lastIndexOf("/", url.length));
url = url + "/Post.aspx?ID=" + $(this).attr("ows_ID");
}



var link = "<p>" + "<a href='" + url + "'>" + $(this).attr("ows_Title") + "</a>" + "</p>";
$("#sitecollectionlink").append(link);
});
}
});
});
</script>

<span id="sitecollectionlink">Test1</span>
May 29, 2012 at 12:05 PM

A few thoughts I have would be to check to see if you are getting a javascript error in Firebug. Also, I always leave the language attribute of the script tag in place as I have seen cases where the script will not work without it. <script type='text/javascript' language='javascript'>. I also do not see where you are loading the jQuery library though I know you say it works in IE, but something is definitely amiss in other browsers.

May 29, 2012 at 12:10 PM

I think I've figure out what the issue is and that it is authentication.

When in fiddler with the content editor on the page i get a nice blue line to say authentication issue but when I remove it, there aren't any problems.

I'm not a coding, anyone able to help me out with the code?

Thanks

Coordinator
May 29, 2012 at 12:48 PM

The code looks fine (no way to test on this end, of course), and if it works in IE, then you know it is written correctly.

So I agree that it's probably an authentication thing. Those are tougher to debug, and if you can get some help with it from someone who can trace through what Fiddler's telling you, then that's probably the best next step.

It's very odd that you aren't getting the alert in the other browsers. You should see *something*. Check that the jQuery file (wherever it is referenced) and the SPServices file in SiteAssets are available for read to everyone. If you add an alert just below the $(document).ready(function(){ line, it'll tell you is jQuery is even being loaded in the other browsers.

M.

Apr 15, 2015 at 3:23 PM
Use $(xData.responseText).SPFilterNode("z:row") in place of $(xData.responseXML).SPFilterNode("z:row") in the above code to work in chrome.
Coordinator
Apr 15, 2015 at 4:24 PM
$(xData.responseXML).SPFilterNode("z:row")
should work in all browsers.

Note that this post is about 3 years old.

M.