问题描述
下面的代码看似执行网络服务并返回值,但忽略了 where 子句(从而返回列表中的所有项目).这是我提出的问题的最简单形式.
The code below seemingly executes the web service and returns values, but ignores the where clause (thus returning all items in the list). This is the simplest form of the problem that I've come up with.
TestQuery 列表是一个简单的自定义列表,没有用户定义的字段.谁能看出过滤器不起作用的原因?
The TestQuery list is a simple custom list with no user defined fields. Can anyone see why the filter is not working?
<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>
推荐答案
您缺少一个 <query>.这些参数的格式有点违反直觉.
You're missing a <query>. The formatting of those parameters is somewhat counterintuitive.
我的博客上有一篇文章,里面有一个工作示例:
There's a post on my blog with a working example:
http:///tqcblog.com/2007/09/24/sharepoint-blog-content-rating-with-javascript-and-web-services
这篇关于GetListItems Web 服务忽略我的查询过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!