简体   繁体   English

使用spservices搜索列表

[英]using spservices to search a list

I am trying to search a sharepoint list called mollyList. 我正在尝试搜索名为mollyList的共享点列表。 It has column name Food, Calories, weight... ect. 它具有列名称食物,卡路里,重量...等。 I modified this sample code below, but I keep getting an error: POST /_vti_bin/Lists.asmx 500 (Internal Server Error) 我在下面修改了此示例代码,但始终出现错误:POST /_vti_bin/Lists.asmx 500(内部服务器错误)

And I have no idea what is the issue? 而且我不知道这是什么问题? Can someone check out my code? 有人可以签出我的代码吗?

 <!-- 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>

Your sendQuery() function looks wrong to me, specifically these two lines: 您的sendQuery()函数在我看来错了,特别是这两行:

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

It's not clear what listName: $(this).attr("mollyList"), is achieving for you. 目前尚不清楚listName: $(this).attr("mollyList"),正在为您实现什么。 If you already know that the list name is "mollyList" then the correct code should be listName: "mollyList", 如果您已经知道列表名称为“ mollyList”,则正确的代码应为listName: "mollyList",

If you're trying to access a list on a different site, then webURL should be the URL of the site on which the list resides, presumably in the following syntax: webUrl: "http://server.com/site/web", 如果您尝试访问其他站点上的列表,则webURL应该是列表所在站点的URL,大概使用以下语法: webUrl: "http://server.com/site/web",

The documentation for the GetListItems operation suggests that listName should be the display name of your list, while webURL is optional if you're executing the code on the site where the list resides. GetListItems操作的文档建议listName应该是列表的显示名称,而webURL是可选的(如果要在列表所在的站点上执行代码)。

Also note that if you're working with SharePoint 2010 or above, you also have the built-in JavaScript object model that you can work with. 另请注意,如果您使用的是SharePoint 2010或更高版本,则还具有可以使用的内置JavaScript对象模型。 You can find Microsoft's documentation on the JavaScript client object model here: https://msdn.microsoft.com/en-us/library/hh185015(v=office.14).aspx 您可以在此处找到有关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