SharePoint GetListItems Across Domain

淺唱寂寞╮ 提交于 2019-12-13 03:17:37

问题


I basically need to perform a GetListItems from a SharePoint list on a different server. I have tried different codes but they all error out. Can someone look at what I have and see if it's wrong or if it's just not possible? I get the Error alert then an xData.ResponseText alert as 'undefined'. Nothing after that. The server where I'm running the code is server3.intranet.com. Thank you.

var soapEnv =
    "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
        <soapenv:Body> \
             <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                <listName>Shared Documents</listName> \
                <viewFields> \
                    <ViewFields> \
                        <FieldRef Name='Title' /> \
                   </ViewFields> \
                </viewFields> \
            </GetListItems> \
        </soapenv:Body> \
    </soapenv:Envelope>";

function Result(xData, status) {
    alert(xData.responseText);
    $(xData.responseXML).find("z\\:row").each(function() {
        var title = $(this).attr("ows_Title");
        alert(title);
    });
}

    $.ajax({
    url: "http://teams02.intranet.com/sites/MySite/_vti_bin/Lists.asmx",
    type: "POST",
    dataType: "JSONP",
    crossDomain: true,
    data: soapEnv,
    complete: Result,
        contentType: "text/xml; charset=\"utf-8\"",
 error:function(){
     alert("Error");
 }

So is there anything that needs to be changed in this code? And is the url that I'm using correct? I'm not sure exactly what I should be pointing this at--if it's the list itself or some sort of virtual path.


回答1:


Here is a working example:

$(function(){
    var soapEnv = 
    "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
        <soapenv:Body> \
            <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                <listName>Shared Documents</listName> \
                <viewFields> \
                    <ViewFields> \
                        <FieldRef Name='Title' /> \
                    </ViewFields> \
                </viewFields> \
            </GetListItems> \
        </soapenv:Body> \
     </soapenv:Envelope>";
    $.ajax({
        url: "http://servername/mysite/_vti_bin/lists.asmx",
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        contentType: "text/xml; charset=\"utf-8\"",
        complete: function(xData, status){
            $(xData.responseXML).find("z\\:row").each(function(){
                var title = $(this).attr("ows_FileLeafRef").split("#")[1];
                alert(title);
            })
        },
        error: function(){
            alert("error");
        }
    });
});



回答2:


You're risking to face a cross site scripting. In order to accomplish your goal I'd advice you to create a service on the same server your javascript comes from and implement all the logic to retrieve data from the other server in this local service (i.e. using Linq2SharePoint or SOAP API). This would be the most reliable way from the point of view of the security and cross-browser implementation.



来源:https://stackoverflow.com/questions/9469980/sharepoint-getlistitems-across-domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!