Trying to access share point GetListItems services using spservices

Mar 22, 2012 at 1:54 PM

I am getting '401 Unauthorized status code' when i try to access sharepoint GetListItems services using spservices. Bu i am able to access services through browser.

Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="js/jquery.SPServices-0.6.2.min.js"></script>
<script language="javascript" type="text/javascript">

 $(document).ready(function() {
   $().SPServices({
     operation: "GetListItems",
     webURL: "http://xxx-xxxxx/Lists/bcs_list1/Read%20List.aspx",    
     async: false,
     listName: "{CB450228-4E32-47DB-A5AB-115B937660A0}",
     CAMLViewFields: "<ViewFields><FieldRef Name='Name' /></ViewFields>",
     completefunc: function (xData, Status) {
       $(xData.responseXML).SPFilterNode("z:row").each(function() {
         var liHtml = "<li>" + $(this).attr("ows_Name") + "</li>";
         $("#tasksUL").append(liHtml);
       });
     }
   });
 });
 
</script>

</head>
<body>
<ul id="tasksUL" > </ul>
</body>
</html>

Mar 22, 2012 at 2:02 PM
You lost me when you stated that you are "able to access services through browser".... Where are you getting the 401 error? Are you trying to access the webservices from some other program that is not the browser?

_____
Paul

Sent from mobile device.

Mar 22, 2012 at 2:09 PM

I mean I am able to access webservice through direct web URL: "http://..."  when i run above HTML code i am getting 401 error.. 

Mar 22, 2012 at 2:22 PM

Ahh.. Ok.. .Got it now... :)

Looking at your example code, the webURL does not seem correct... It is suppose to point to the Site URL... you seem to have it pointed at a custom aspx page...  from your example, it should be http://xxx-xxxxx... From the SPServices documentation (here):

webURL
For Web Service operations where it makes sense, you can pass in a webURL to change the context for the AJAX call. By default, the current site (as determined by $().SPServices.SPGetCurrentSite) is used.

 

Try the following:

 

$(document).ready(function() {
   $().SPServices({
     operation: "GetListItems",
     webURL: "http://xxx-xxxxx",    
     async: false,
     listName: "{CB450228-4E32-47DB-A5AB-115B937660A0}",
     CAMLViewFields: "<ViewFields><FieldRef Name='Name' /></ViewFields>",
     completefunc: function (xData, Status) {
       
       alert("Status of XML message reaching Sharepoint webservice: " + Status);
       alert("Response from server: " + xData.responseText);
       
       
       $(xData.responseXML).SPFilterNode("z:row").each(function() {
         var liHtml = "<li>" + $(this).attr("ows_Name") + "</li>";
         $("#tasksUL").append(liHtml);
       });
     }
   });
 });

 

 

I assume the following is true:

  1. The code you posted is hosted on a page that is under the same domain (http://xxx-xxxxx)
  2. I assume "{CB450228-4E32-47DB-A5AB-115B937660A0}" is the UID for list name "bcs_list1" in your Site

 

Paul.

Mar 26, 2012 at 6:29 AM

Yours assumptions are true, Still I am facing same issue

Alert output:

Status of XML message reaching Sharepoint webservice: error

Response from server: undefined

Coordinator
Mar 26, 2012 at 1:00 PM

What this says is that you aren't even getting a real response from the server.

My guess is that you still don't have the right values for webURL and/or listName. If the list is in the site where you have the script, you don't need the webURL at all. I'd suggest another read through the docs.

M.