提前输入预取怪异行为 [英] typeahead prefetch weird behaviour

查看:133
本文介绍了提前输入预取怪异行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Twitter的预输入的非常基本的设置.我有2个不同的搜索字段,因此有两个预先输入的提示字词.

I'm using a very basic setup of Twitter's typeahead. I have 2 different search fields, hence the two typeahead initalizations.

JavaScript:

Javascript:

$(document).ready(function() {
    $('input.search-event').typeahead({
        name: 'Events',
        prefetch: '/media/json/events.json',
        ttl: 0,
        limit: 10
    });

    $('input.search-artist').typeahead({
        name: 'Artists',
        prefetch: '/media/json/artists.json',
        ttl: 0,
        limit: 10
    });
});

events.json和artist.json都被格式化为["entry1", "entry2", "entry3", "..."].

Both events.json and artists.json are formatted as ["entry1", "entry2", "entry3", "..."].

在Chrome的正常模式和隐身模式下,我得到不同的结果.在正常模式下,它似乎正在使用一个不再存在的旧json文件(我已将其删除).在隐身模式下,它使用正确的json文件,但不会自动建议添加到json文件中的最后一项.我希望将ttl设置为0可以解决此问题,但事实并非如此.我已经清除了浏览器缓存,但这不能解决问题.我读过其他文章,我应该清除浏览器的localStorage,但我真的不知道如何.控制台日志中没有错误.

I get different results in normal and incognito mode in Chrome. In normal mode it seems to be using an old json file that doesn't exist anymore (I've deleted it). In incognito mode it uses the correct json file, but it doesn't autosuggest the last item added to the json file. I was hoping ttl set to 0 would solve this problem but it doesn't. I've cleared my browser cache but that doesn't resolve the problem. I've read in other posts that I should clear my browser's localStorage but I don't really know how. There are no errors in the console log.

我刚刚发现FF和Safari中,typeahead根本不显示任何内容:-)

And I've just found out that typeahead is not showing anything at all in FF and Safari :-)

结果似乎也取决于name:值.那应该发生吗?例如:如果我将name:值更改为'test',则提前输入根本不起作用.

The results also seem to be depending on the name: value. Is that supposed to happen? For instance: if I change the name: value to 'test' typeahead doesn't work at all.

推荐答案

键入确实可在FF和Safari中使用.而没有name的事实对您不起作用(对我而言)表明(json)您的json文件中有某些错误,并且以前并非如此,并且您的浏览器正在使用缓存版本.

Typeahead does work in FF and in Safari. And the fact the without a name it doesn't work for you suggests (to me) that something in your json file is wrong, and that it didn't use to be the case, and that your browser is using a cached version.

由于name是缓存的键,因此可能解释了您所看到的一切:

Since name is the key to the cache, that might explain everything you're seeing:

  • 无法在隐身模式下工作,因为本地存储未用于隐身模式,并且json文件本身存在问题.
  • 不能使用其他名称,因为在缓存中找不到具有不同名称的数据集(同样,json文件在某种程度上是错误的).
  • 在FF和Safari中不起作用-相同的原因:json不好,他们还没有任何缓存.

要进行调试,请先在网络标签下的Chrome(F12)中查看开发人员工具,然后查看对/media/json/artists.json的请求和响应,并确保它们没有问题.然后确保内容确实是有效的JSON.

To debug, start with looking in the Developer Tools in Chrome (F12) under the network tab, and see the request and response to /media/json/artists.json, and make sure they are OK. Then make sure the content is indeed valid JSON.

这篇关于提前输入预取怪异行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆