繁体   English   中英

使用spservices搜索列表

[英]using spservices to search a list

我正在尝试搜索名为mollyList的共享点列表。 它具有列名称食物,卡路里,重量...等。 我在下面修改了此示例代码,但始终出现错误:POST /_vti_bin/Lists.asmx 500(内部服务器错误)

而且我不知道这是什么问题? 有人可以签出我的代码吗?

 <!-- begin snippet: js hide: false --> 
 <body> <table><tbody><tr><td align="right">Calories</td> <td align="left"><input id="firstName" type="text"/></td></tr> <tr><td align="right">weight:</td> <td align="left"><input id="wt" type="text"/></td></tr> <tr><td align="right">weight:</td> <td align="left"><input id="wt2" type="text"/></td></tr></tbody></table> <p><input id="sb" type="button" value="Search"/> </p> <ul id="searchResults"></ul> </body> 

$(document).ready(function () {
$("#sb").click(function(){
    alert("this");
$("#searchResults").empty();
var query = "";
var key = "";

//Build Query from input
if($("#firstname").val()){
key = $("#firstname").val();
query = "<Query><Where><Or><Contains><FieldRef Name='Food'/><Value Type='Text'>"+ key +"</Value></Contains><Contains><FieldRef Name='calories'/><Value Type='Text'>"+ key +"</Value></Contains></Or></Where></Query>";
}

// Pass query to Function
if(query)
sendQuery(query);
else
$("#searchResults").append("Please enter atleast one value");

//If no results found
if (!$("#searchResults").html())
{
$("#searchResults").append("No Results Found");
}

});
});

function sendQuery(spQuery)
{
var thisSite = $().SPServices.SPGetCurrentSite();
//function to get all the lists
$().SPServices({
operation: "GetListItems",
async:false,
webURL: $(this).attr("/Lists/mollyList/AllItems.aspx"),
listName: $(this).attr("mollyList"),
CAMLQuery: spQuery,
CAMLRowLimit: 100,   
completefunc: function(xData, Status) {

}
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<body>
<table><tbody><tr><td align="right">Look Up:</td>
<td align="left"><input id="firstname" type="text"/></td></tr>
</tbody></table>
<p><input id="sb" type="button" value="Search"/> </p>
<ul id="searchResults"></ul>
Generate SPQuery and pass to the function: 



</body>

您的sendQuery()函数在我看来错了,特别是这两行:

webURL: $(this).attr("/Lists/mollyList/AllItems.aspx"),
listName: $(this).attr("mollyList"),

目前尚不清楚listName: $(this).attr("mollyList"),正在为您实现什么。 如果您已经知道列表名称为“ mollyList”,则正确的代码应为listName: "mollyList",

如果您尝试访问其他站点上的列表,则webURL应该是列表所在站点的URL,大概使用以下语法: webUrl: "http://server.com/site/web",

GetListItems操作的文档建议listName应该是列表的显示名称,而webURL是可选的(如果要在列表所在的站点上执行代码)。

另请注意,如果您使用的是SharePoint 2010或更高版本,则还具有可以使用的内置JavaScript对象模型。 您可以在此处找到有关JavaScript客户端对象模型的Microsoft文档: https : //msdn.microsoft.com/zh-cn/library/hh185015(v=office.14).aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM