[英]get JSON file on input change only once
I have a JSON file on my backend with suggested words for autocomplete in the search. 我的后端有一个JSON文件,其中包含用于自动完成搜索的建议字词。
I don`t want the JSON to load every time the page loads (for performance), I want only when someone wants to use the search. 我不想每次页面加载时(为了提高性能)都加载JSON,我只想在有人要使用搜索时加载。
For autocomplete, I am using bootstrat3-typeahead ( https://github.com/bassjobsen/Bootstrap-3-Typeahead ) 对于自动完成功能,我正在使用bootstrat3-typeahead( https://github.com/bassjobsen/Bootstrap-3-Typeahead )
this is the script that loads the json: 这是加载json的脚本:
var searchSuggest = "http://localhost/searchSuggest.json";
$.get(searchSuggest, function(data){
$("#input-search").typeahead({
source:data,
autoSelect: false,
afterSelect: function(){
// local function the commits the search
search($("#input-search"))
}
});
I was thinking about loads the JSON on input change event, but how can I get it only once? 我当时正在考虑在输入更改事件上加载JSON,但是如何只能获取一次呢?
您可以使用$ .one来使输入更改的事件处理程序仅执行一次: http : //api.jquery.com/one/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.