Skip to content

Instantly share code, notes, and snippets.

@devendrasv
Last active December 15, 2015 21:29
Show Gist options
  • Save devendrasv/5325970 to your computer and use it in GitHub Desktop.
Save devendrasv/5325970 to your computer and use it in GitHub Desktop.
$(document).ready(function () {
var e = ExecuteOrDelayUntilScriptLoaded(
SearchStudents,
"sp.js");
});
function SearchStudents() {
$("#SearchStudentsDiv").show();
}
function executeQuery(query) {
Results = {
element: '',
url: '',
init: function (element) {
Results.element = element;
Results.url = _spPageContextInfo.webAbsoluteUrl +
"/_api/search/query?querytext='" + query + "'";
},
load: function () {
$.ajax(
{
url: Results.url,
method: "GET",
headers: {
"accept": "application/json;odata=verbose",
},
success: Results.onSuccess,
error: Results.onError
}
);
},
onSuccess: function (data) {
var results =
data.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results;
var html = "<table>";
for (var i = 0; i < results.length; i++) {
html += "<tr><td>";
html += results[i].Cells.results[3].Value;
html += "</td><td>"
html += results[i].Cells.results[6].Value;
html += "</td><tr>";
}
html += "</table>";
Results.element.html(html);
},
onError: function (err) {
alert(JSON.stringify(err));
}
}
Results.init($('#StudentsSearchresultsDiv'));
Results.load();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment