jquery - using spservices to search a list -


i trying search sharepoint list called mollylist. has column name food, calories, weight... ect. modified sample code below, keep getting error: post /_vti_bin/lists.asmx 500 (internal server error)

and have no idea issue? can check out 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 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 function if(query) sendquery(query); else $("#searchresults").append("please enter atleast 1 value");  //if no results found if (!$("#searchresults").html()) { $("#searchresults").append("no results found"); }  }); });  function sendquery(spquery) { var thissite = $().spservices.spgetcurrentsite(); //function 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 , pass function:     </body> 

your sendquery() function looks wrong me, these 2 lines:

weburl: $(this).attr("/lists/mollylist/allitems.aspx"), listname: $(this).attr("mollylist"), 

it's not clear listname: $(this).attr("mollylist"), achieving you. if know list name "mollylist" correct code should listname: "mollylist",

if you're trying access list on different site, weburl should url of site on list resides, presumably in following syntax: weburl: "http://server.com/site/web",

the documentation getlistitems operation suggests listname should display name of list, while weburl optional if you're executing code on site list resides.

also note if you're working sharepoint 2010 or above, have built-in javascript object model can work with. can find microsoft's documentation on javascript client object model here: https://msdn.microsoft.com/en-us/library/hh185015(v=office.14).aspx


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -