dimanche 1 février 2015

How to create a search using sharepoint JSOM

I'm new to Sharepoint and jsom and i'm trying to build up a search using JSOM.


and i tried below code snippts


1st step: Create a page and added following HTML


Search: ​ ​​

​​​​


i linked jquery and abc.js file succesfully


and added this JS code to abc.js file


'use strict';


var results;


var context = SP.ClientContext.get_current(); var user = context.get_web().get_currentUser();


// This code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model $(document).ready(function () {



$("#searchButton").click(function () {

alert('check1');
var keywordQuery = new Microsoft.SharePoint.Client.Search.Query.KeywordQuery(context);
keywordQuery.set_queryText($("#searchTextBox").val());

alert('check2');

var searchExecutor = new Microsoft.SharePoint.Client.Search.Query.SearchExecutor(context);
results = searchExecutor.executeQuery(keywordQuery);

context.executeQueryAsync(onQuerySuccess, onQueryFail)
});


});


function onQuerySuccess() { $("#resultsDiv").append('');



$.each(results.m_value.ResultTables[0].ResultRows, function () {
$("#resultsDiv").append('<tr>');
$("#resultsDiv").append('<td>' + this.Title + '</td>');
$("#resultsDiv").append('<td>' + this.Author + '</td>');
$("#resultsDiv").append('<td>' + this.Write + '</td>');
$("#resultsDiv").append('<td>' + this.Path + '</td>');
$("#resultsDiv").append('</tr>');
});

$("#resultsDiv").append('</table>');


}


function onQueryFail(sender, args) { alert('Query failed. Error:' + args.get_message()); }


In this code check1 alert is coming but not the check2 alert.. Whats the wrong with this..?


Please help me


Thank you very very much


Aucun commentaire:

Enregistrer un commentaire