跨域的SharePoint GetListItems [英] SharePoint GetListItems Across Domain

查看:112
本文介绍了跨域的SharePoint GetListItems的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上需要从其他服务器上的SharePoint列表执行GetListItems.我尝试了不同的代码,但是它们都出错了.有人可以看一下我所拥有的东西,看看是错的还是根本不可能的?我收到错误警报,然后收到xData.ResponseText警报为未定义".在那之后没有.我运行代码的服务器是server3.intranet.com.谢谢.

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.

推荐答案

下面是一个有效的示例:

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");
        }
    });
});

这篇关于跨域的SharePoint GetListItems的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆