I have an autocomplete plug-in (DevBridge AutoComplete) on my text box.
$('#myTextBox').autocomplete({
serviceUrl: '/Handler/Autocomplete.ashx?'
});
It is making the Ajax call (I can see the JSON return in Fiddler), and I am getting a return like this:
[{"Key":39,"Value":"118"},{"Key":40,"Value":"155"},{"Key":2,"Value":"16"}]
but I keep getting an error:
Unable to get property 'length' of undefined or null reference
On this part of the code:
verifySuggestionsFormat: function (suggestions) {
// If suggestions is string array, convert them to supported format:
if (suggestions.length && typeof suggestions[0] === 'string') {
return $.map(suggestions, function (value) {
return { value: value, data: null };
});
}
return suggestions;
}
I'm not sure what this means. Can someone tell me how to fix this? Is it just syntax? I'm not sure where/how to add these suggestions...
suggestions
is null or undefined.
Before inspecting the variable, test that it exists:
if (!suggestions) return;
For example:
verifySuggestionsFormat: function (suggestions) {
// Fail fast if suggestions is not valid
if (!suggestions) return;
// If suggestions is string array, convert them to supported format:
if (suggestions.length && typeof suggestions[0] === 'string') {
return $.map(suggestions, function (value) {
return { value: value, data: null };
});
}
return suggestions;
}