I'm using typeahead
auto suggestion for my application but the problem is ajax function exists in bookingAjaxFunc
function and bookingAjaxFunc
code is
function bookingAjaxFunc(url, bookingId, jsonCall) {
switch(jsonCall) {
case 'Add':
values = $('.booking-form').serializeArray();
break;
case 'autoSuggestion':
values = {bookingId: bookingId, jsonCall: jsonCall};
break;
}
$.ajax({
url: url,
type: 'POST',
dataType: 'json',
data: values,
cache: false,
success: function(data) {
switch(jsonCall) {
case 'Add':
console.log(data);
break;
case 'autoSuggestion':
console.log(data);
break
}
}
});
}
this is my ajax function which is working fine in insert, update, delete and other cases but now I want to call this function in typeahead
how could I do this? and my typeahead
function is working fine in predefined values but now I want to call my bookingAjaxFunc
I couldn't figure out where to call my function, and remember this function is copy from an example and I paste it here as it as.
function substringMatcher(strs) {
return function findMatches(q, cb) {
var matches, substrRegex;
// an array that will be populated with substring matches
matches = [];
// regex used to determine if a string contains the substring `q`
substrRegex = new RegExp(q, 'i');
// iterate through the pool of strings and for any string that
// contains the substring `q`, add it to the `matches` array
$.each(strs, function (i, str) {
if (substrRegex.test(str)) {
// the typeahead jQuery plugin expects suggestions to a
// JavaScript object, refer to typeahead docs for more info
matches.push({ value: str });
}
});
cb(matches);
};
}
var states = ['Alabama', 'Alaska'];
$('.autoSuggestion').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'states',
displayKey: 'value',
source: substringMatcher(states)
});
The bookingAjaxFunc
function which create for my ajax call so where I use my this code for passing values to my function and use my case
var url = $("#do").val();
bookingAjaxFunc(url, '', 'autoSuggestion');
I also try to add remote
below source
but didn't work.
Thanks