GetListItems Webservice忽略我的查询过滤器

时间:2009-05-07 15:32:45

标签: jquery web-services sharepoint

下面的代码似乎执行Web服务并返回值,但忽略了where子句(从而返回列表中的所有项)。这是我提出的最简单的问题形式。

TestQuery列表是一个简单的自定义列表,没有用户定义的字段。任何人都可以看到过滤器无法正常工作的原因吗?

<body>
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    var soapEnv = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'><soapenv:Body><GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>";
    soapEnv += "<listName>TestQuery</listName>";
    soapEnv += "<Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>One</Value></Eq></Where></Query>";
    soapEnv += "<ViewFields><ViewFields><FieldRef Name='Title'/></ViewFields></ViewFields><RowLimit>1</RowLimit>";
    soapEnv += "</GetListItems></soapenv:Body></soapenv:Envelope>";

    $.ajax({
        url: "_vti_bin/lists.asmx",
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        complete: processResult,
        contentType: "text/xml; charset=\"utf-8\""
    });
});

function processResult(xData, status) {
            $('#WSResponse').text(status);
    $(xData.responseXML).find("z\\:row").each(function() {
        var liHtml = "<li>" + $(this).attr("ows_Title") + "</li>";
        $("#tasksUL").append(liHtml);
    });
    //}
}
</script>


<ul id="tasksUL"/>
<div id="WSResponse"/>

</body>

3 个答案:

答案 0 :(得分:4)

我认为您需要将Query标记放在查询标记内,并将ViewField放在viewField标记内,如下所示:

var soapEnv = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'><soapenv:Body><GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>"; 
    soapEnv += "<listName>TestQuery</listName>"; 
    soapEnv += "<query><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>One</Value></Eq></Where></Query></query>"; 
    soapEnv += "<viewFields><ViewFields><FieldRef Name='Title'/></ViewFields></viewFields><RowLimit>1</RowLimit>"; 
    soapEnv += "</GetListItems></soapenv:Body></soapenv:Envelope>"; 

答案 1 :(得分:3)

您错过了&lt; query&gt;。这些参数的格式有点违反直觉。

我的博客上有一个帖子,上面有一个工作示例:

http://tqcblog.com/2007/09/24/sharepoint-blog-content-rating-with-javascript-and-web-services

答案 2 :(得分:2)

我也面临同样的问题..'Temple的解决方案已经解决了查询问题..但为了使RowLimit工作,我使'R'小写,即

<rowLimit> not <RowLimit>

这抓住了我相当长的时间...... :)快乐的编码......

相关问题