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

GetListItems - Error Reporting

Apr 4, 2011 at 7:40 PM

Hi first of all I would just like to say I am loving SPServices has open so many doors for me and I have only scratched at the surface.

The first thing that I have been working on is bringing lists from one SharePoint Intranet site to another; and I noticed that depending on the computer that views the webpart may ask the user to log in which if they cannot log in or decide to press cancel obviously the list is not brought in and cannot be viewed.

So I thought I would share this for you all 

The part that does this is the (if statement) one thing I did was to add into the DIV initially from Ajax Loader

Hope this helps someone =] 

script> $(document).ready(function(){ var i = 1; $().SPServices({ operation: "GetListItems", async: true, listName: "", CAMLRowLimit: 3, CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>", completefunc: function (xData, Status) { if (xData.responseXML.getElementsByTagName("z:row").length == 0) { $("#result").append('Sorry but an error occured recieving the data'); } else { $(xData.responseXML).find("[nodeName=z:row]").each(function() { var formTitle = $(this).attr("ows_Title"); $("#result").append(formTitle); }); } } }); }); </script> <div id="result"></div>

Apr 4, 2011 at 7:47 PM

Thanks for sharing, ToxicD.

Error handling techniques vary by application, of course. I some cases, you'll want to show a message to the user and in other cases, you'll want to fail silently.

BTW, make sure you use single quotes arounf the z:row here: .find("[nodeName='z:row']").


Apr 4, 2011 at 9:01 PM

Yeah for the particular thing I was working on I needed it to come back and say something as otherwise they would sit there confused as for the z:row thanks for the heads up =);

I did get a bit confused with that wasn't sure if it was if your using jQuery 1.5+ to use it and anything less use without or not?

Apr 4, 2011 at 9:10 PM

The 'z:row' thing is required in 1.5+, but was recommended previously. (It was actually a bug in jQuery that it wasn't required in 1.4.x.) It's a requirement for all strings inside selector text, in fact.


Apr 4, 2011 at 9:22 PM

ah I see =] thank you for the heads up