- 主题:关于jQuery的get()方法
请问一下:
我现在用
function myFun(){
$.get("mytext.txt",null,function(txt){...});
}
这种方式来加载mytext.txt里的内容,然后根据用户的输入来搜索txt里的内容输出。
问题是:每次调用函数都会重新加载mytext.txt文件,是么?
txt有点大。有没有什么办法让它只加载一次,只要不是刷新整个页面,以后的话每次都不要再重新去加载?
求指点,最好能直接给出代码参考。
感谢!
--
FROM 134.134.139.*
有缓存的
--
FROM 219.134.215.*
就是说我不用特别去作一些处理,只要页面不刷新,用户点击多次按钮调用这个函数时,txt文件是不会去重新下载的?
【 在 zxdong262 的大作中提到: 】
: 有缓存的
--
FROM 134.134.139.*
理论上是这样,你可以从ff或者chrome控制台查看第二次请求返回状态是不是304
【 在 cowell 的大作中提到: 】
: 就是说我不用特别去作一些处理,只要页面不刷新,用户点击多次按钮调用这个函数时,txt文件是不会去重新下载的?
:
--
FROM 219.134.215.*
The browser may not send a request at all, according to its cache rules.
I on the other hand have an application that needs to reload an image
over and over, but at first the browser sends almost only the first request.
Then Google told me to bypass the cache by appending the URL with "#...".
【 在 zxdong262 (html5beta.com) 的大作中提到: 】
: 理论上是这样,你可以从ff或者chrome控制台查看第二次请求返回状态是不是304
--
FROM 59.78.37.*
要是不想缓存就加时间戳.
【 在 XeCycle 的大作中提到: 】
: The browser may not send a request at all, according to its cache rules.
: I on the other hand have an application that needs to reload an image
: over and over, but at first the browser sends almost only the first request.
: ...................
--
FROM 219.134.215.*
jquery.ajax()可以传入一个选项 `cache = false`
【 在 XeCycle (据说是小 X) 的大作中提到: 】
: The browser may not send a request at all, according to its cache rules.
: I on the other hand have an application that needs to reload an image
: over and over, but at first the browser sends almost only the first request.
: ...................
--
FROM 117.30.118.*
不知道这个具体怎么用,不懂ajax。
但我发现只要我一手动改txt文件,在页面显示的结果是更改后的。所以,get()是每次都在重新加载。
我现在索性把代码改成$(document).ready()时用get()把txt内容读到隐藏的一个<div>里,然后响应页面请求时就从这个div中拿数据来显示结果,哈哈。虽然笨拙了点,但算是满足我的需要了。
:)
【 在 hgoldfish 的大作中提到: 】
: jquery.ajax()可以传入一个选项 `cache = false`
:
--
FROM 192.55.54.*