3

I'm calling a SharePoint Web Service (Webs.asmx) with JQuery to get a list of all subsites:

$(document).ready(function() {
        var hrefParts = window.location.href.split('/');
        var wsURL = "";
        for (i = 0; i < (hrefParts.length - 2); i++) {
            if (i > 0)
                wsURL += "/";
            wsURL += hrefParts[i];
        }
        wsURL += "/_vti_bin/Webs.asmx";
        var soapEnv =
            "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
                <soapenv:Body> \
                    <GetAllSubWebCollection xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                    </GetAllSubWebCollection > \
                </soapenv:Body> \
            </soapenv:Envelope>";

        $.ajax({
            url: wsURL,     
            beforeSend: function  (xhr) {  
 xhr.setRequestHeader("SOAPAction",  "http://schemas.microsoft.com/sharepoint/soap/GetAllSubWebCollection");
},
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            complete: processResult,
            error:function(xhr,err){ 
    alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status); 
    alert("responseText: "+xhr.responseText); 
},
            contentType: "text/xml; charset=\"utf-8\""
        });

    });

    function processResult(xData, status) {
        ...
    }

However, I always get a login problem due to the beforeSend call. If I comment it out, I get an "Access Denied" error page from SharePoint. I have "Full Control" access to the site and all subsites. Calling a different web service (e.g. calling GetListCollection from lists.asmx) is successful.

What could be the problem here?

2
  • Some questions: Where is the page that holds the javascript? In a document library somewhere? Is the login problem a 401 Unauthorized error? Commented Feb 3, 2010 at 18:19
  • It's inside a "Pages" library. Problem solved now as stated at the answer below. Commented Feb 4, 2010 at 0:56

1 Answer 1

3

This operation requires Site Collection Administrator access, even Full Control is not enough.

You will probably need to iterate thru GetWebCollection instead, or create a proxy page that runs with elevated privileges and returns the webservice response.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.