used JavaScript plugins and created my own helper functions, now I like to create my own plugin that can be used site wide by creating an object and calling its methods. There seems to be lots of different ways to do this, and I am getting confused.
Hoping someone could take a look at my approach and advise, and possibly give me some good links to read through.
function AnswerQuestion(query) {
this.query = query;
this.template = 'answers_searchresult';
this.container = '#answers';
this.SearchForAnswer = function () {
var O = this;
$.ajax({
type: "POST",
datatype: 'json',
url: "/WebServices/GlobalWebService.asmx/AnswersSearch",
data: JSON.stringify({ q: this.query }),
contentType: 'application/json; charset=utf-8',
success: function (data) {
O.SearchForAnswerSuccess(data.d);
},
error: function (data) { log("Answers Search Fail"); }
});
};
this.SearchForAnswerSuccess = function (data) {
var template = Handlebars.template[this.template];
$(this.container).append(template(data));
};
}
Is there anything wrong with what Im doing? My outcome is to have a plugin i can initalise on any page to activate a search and present results.