AutoComplete (jQuery UI) and localstorage

I just get a weird error when using these two tools. I make an AJAX request to the API and then retrieve the JSON data that is stored in localStorage and displayed in the autocomplete panel. The problem is that according to the source of the autocomplete source, the panel will react differently.

Here is the callback function caused by the success of AJAX:

function _company_names(data)
{
    localStorage.setItem('ac_source', JSON.parse(data).Result);

    // Works fine
    $("#search_input").autocomplete( "option", "source", JSON.parse(data).Result);
    // Send an AJAX request
    $("#search_input").autocomplete( "option", "source", localStorage.getItem('ac_source'));
}

If I pass JSON.parse (data). The result as a result for the autocomplete source, this will be normal. However, if I pass localStorage.getItem ('ac_source'), the widget ac will send an AJAX request (without using my own function) blowing in the wind (my node.js will try to parse it, etc.).

I use localstorage to access this data from another part of my code (keep it for comparison with other user studies and display them if the request is the same).

+3
source share
1 answer

Only local data can be stored in local storage:

localStorage.setItem('ac_source', '{"key":"data","key1":"data1"}');

$("#search_input").autocomplete( "option", "source", JSON.parse(localStorage.getItem('ac_source')).Result);
+2
source

All Articles