【问题标题】:result.responseXML is undefined on ajax getItems from Sharepoint list call来自 Sharepoint 列表调用的 ajax getItems 上未定义 result.responseXML
【发布时间】:2012-05-14 22:58:01
【问题描述】:

我正在编写一个脚本以使用 ajax 从 Sharepoint 列表中获取一些项目。我一直在努力让这个工作两周。虽然我之前已经成功完成了这个,但在这个我不知道我错过了什么。

这是我的代码:

var xmlData ="<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'><soap:Body><GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'><listName>CACF25CF-D392-4A28-A2C6-91D4C72AEE05</listName><query><Query   xmlns=''><Where><Eq><FieldRef Name='ows_LinkTitle' /><Value Type='Text'>";
xmlData+=value;
xmlData+="</Value></Eq></Where></Query></query></GetListItems></soap:Body></soap:Envelope>";

value 变量包含过滤列表所依据的值。

这是我的 ajax 调用:

$.ajax({   
url: "https://mysharepointsite.net/sites/scm/_vti_bin/lists.asmx",   
type: "POST",
dataType: "xml",   
data: xmlData,    
complete:SuccessFuncDetails,   
error: ErrorFunc,
contentType: "text/xml; charset=\"utf-8\""  
});

正如我在标题中所说,此调用的 XML 响应是未定义的,我不知道为什么。我已经使用 u2u CAML 构建器通过 Sharepoint Web 服务连接到该列表并且工作正常。

此外,当我尝试使用 IE 开发人员工具调试脚本时,脚本显示为蓝色,就像文本或注释一样,并且我无法设置断点,尽管脚本已执行。

有人知道为什么会发生这一切吗?谢谢!

【问题讨论】:

    标签: ajax web-services sharepoint caml


    【解决方案1】:

    您的请求中缺少 SOAPAction HTTP 标头,您可以通过在 beforeSend 中设置来添加它:

    $.ajax({
        url: "https://mysharepointsite.net/sites/scm/_vti_bin/lists.asmx",
        type: "POST",
        dataType: "xml",
        data: xmlData,
        complete: SuccessFuncDetails,
        error: ErrorFunc,  
        beforeSend: function (xhr) { xhr.setRequestHeader('SOAPAction', 'http://schemas.microsoft.com/sharepoint/soap/GetListContentTypes'); },
        contentType: "text/xml; charset=\"utf-8\""
    }); 
    

    我还必须稍微修改一下您的查询字符串,确保将其调整到您的列表中:

    var xmlData = "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'><soap:Body><GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'><listName>{823F6320-4698-4CED-B86A-5929A765CCAF}</listName><viewName /><query><Query   xmlns=''><Where><Eq><FieldRef Name='LinkFilename' /><Value Type='Text'>"; 
    xmlData+=value; 
    xmlData+="</Value></Eq></Where></Query></query><viewFields><ViewFields xmlns=''><FieldRef Name='ID' /></ViewFields></viewFields><rowLimit>1000</rowLimit><queryOptions><QueryOptions xmlns=''><ViewAttributes Scope='Recursive' /></QueryOptions></queryOptions></GetListItems></soap:Body></soap:Envelope>";
    

    如果您的网络请求在其他工具中工作,您可以使用Fiddler 来比较输出。

    SharePoint 服务器错误日志有时会指出问题所在。

    我假设您使用的是 SharePoint 2007,如果您只针对 SharePoint 2010,则最好使用 Javascript 中的 Client Object ModelREST services

    【讨论】:

    • 感谢您的回答!我修改了查询并添加了标题,但它仍然无法正常工作。我正在使用 Sharepoint 2007,但我无法访问服务器。是否有其他方法可以从 sharepoint 站点查看错误日志?
    • 我不这么认为。您可以在请求和响应中查看 Fiddler(或 Firebug 的 Net 选项卡,如果您正在使用它)吗?
    • 嘿!很抱歉耽搁了。直到现在我一直在做另一个项目。我已经检查过提琴手,它告诉我找不到该服务。结果是 404。知道为什么吗?我再次提到,使用 CAML 构建器一切运行良好。谢谢!
    • 更新:现在我得到结果 500,抛出了 Microsoft.SharePoint.SoapServer.SoapServerException 类型的异常。值不能为空。
    • 您应该仔细比较 CAML 构建器生成的 http 请求(假设您将它与 web 服务一起使用)和您的 JS 脚本的请求。一定有什么不同...
    猜你喜欢
    • 1970-01-01
    • 2011-07-17
    • 2020-03-10
    • 2021-01-03
    • 2011-01-22
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    相关资源
    最近更新 更多