缓存页面 AJAX 不起作用

发布于 2024-10-04 06:28:59 字数 1181 浏览 5 评论 0原文

每当一个页面同时在 Firefox 和 Webkit 中缓存时,它就会失去所有 ajax 功能。

<html manifest=cache.manifest>
<head>
    <script src="js/jquery.js" type="text/javascript"></script>
    <script src="js/jqtouch.js" type="text/javascript"></script>

无论如何,它只会检索已缓存的页面。有人知道如何解决这个问题吗? 提前致谢! 编辑:Ajax 代码:

    var http = false;
    if(navigator.appName == "Microsoft Internet Explorer") {
      http = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
      http = new XMLHttpRequest();
    } 

  http.open("GET", "default.css", true);
http.setRequestHeader('CacheControl', "no-cache");
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      alert('4(good):'+http.responseText);
    }
  }
  http.send(null);

还使用 jquery $.ajax 进行请求。都不起作用。 JQuery:

    $.ajax({

    url: site_url,

    cache: false,

    dataType: 'html',

    data: ({uuid : devid}),

    success: function(response){

他们总是说成功,但只有在页面被缓存时才返回数据。否则它们返回空“”。

最后一件事:由于服务器端后端相当大,我请求的页面不在清单上。不可能将所有页面都包含在清单中。

基本上,我如何访问不在同一站点 AJAX 清单上的页面。每当我当前尝试时,它总是返回 null。 返回 03:11:41,即使没有缓存等。

Whenever a page is cached in both Firefox and Webkit, it appears to lose all ajax capabilities.

<html manifest=cache.manifest>
<head>
    <script src="js/jquery.js" type="text/javascript"></script>
    <script src="js/jqtouch.js" type="text/javascript"></script>

It will only retrieve pages that have been cached, no matter what. Anyone know how to fix this?
Thanks in advance!
EDIT: Ajax Code:

    var http = false;
    if(navigator.appName == "Microsoft Internet Explorer") {
      http = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
      http = new XMLHttpRequest();
    } 

  http.open("GET", "default.css", true);
http.setRequestHeader('CacheControl', "no-cache");
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      alert('4(good):'+http.responseText);
    }
  }
  http.send(null);

Also using jquery $.ajax for the request. Neither work.
JQuery:

    $.ajax({

    url: site_url,

    cache: false,

    dataType: 'html',

    data: ({uuid : devid}),

    success: function(response){

They always say successful, but only return data if the page is cached. Otherwise they return null "".

One last thing: I am requesting pages not on the manifest, because of a rather large server side backend. It would not be possible to have all pages in the manifest.

Basically, how would I access pages NOT on the manifest on same-site AJAX. Whenever I try currently it always return null.
return 03:11:41, even with no-cache, etc.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

陪你搞怪i 2024-10-11 06:28:59

那不是真的。如果您明确从页面请求数据,它会为您重新下载。您可以通过打开 Firebug 或 Chrome 的调试窗口来检查这一点,并观察浏览器发出 http 请求。

That's not true. If you explicitly request data from a page it re-downloads it for you. You can check this by opening Firebug, or Chrome's debug window and watch the browser make an http request.

三生路 2024-10-11 06:28:59

我一直在尝试让 cache.manifest 工作一段时间,它一直给我类似的响应。我有一个 jquery 移动应用程序,它使用 Web 服务来获取其数据,并且直到我将 Web 服务添加到我的 cache.manifest 文件的 NETWORK 部分后才开始工作

    CACHE MANIFEST
    # This is a comment.
# Cache manifest version 0.1.3.5
# If you change the version number in this comment,
# the cache manifest is no longer byte-for-byte
# identical.




NETWORK:
# All URLs that start with the following lines
# are whitelisted.

Service.svc

CACHE:
# Additional items to cache.

src/jquery-1.6.2.min.js
src/jstorage.min.js
src/jquery.numeric.js
src/jquery.format-1.1.min.js
assets/json2.min.js
assets/jquery.signaturepad.css
assets/jquery.signaturepad.min.js
jquery.mobile-1.0b2/jquery.mobile-1.0b2.min.css
jquery.mobile-1.0b2/jquery.mobile-1.0b2.min.js
jquery.mobile-1.0b2/images/ajax-loader.png
jquery.mobile-1.0b2/images/icon-search-black.png
jquery.mobile-1.0b2/images/icons-18-black.png
jquery.mobile-1.0b2/images/icons-18-white.png
jquery.mobile-1.0b2/images/icons-36-black.png
jquery.mobile-1.0b2/images/icons-36-white.png
src/link-1-3.js
src/events-1-3.js
src/custom-styles.css
Login.html

I've been trying to get cache.manifest working for a while now and it kept giving me similar responses. I have a jquery mobile app that uses a web service to get it's data and wasn't working until I added the web service into the NETWORK section of my cache.manifest file

    CACHE MANIFEST
    # This is a comment.
# Cache manifest version 0.1.3.5
# If you change the version number in this comment,
# the cache manifest is no longer byte-for-byte
# identical.




NETWORK:
# All URLs that start with the following lines
# are whitelisted.

Service.svc

CACHE:
# Additional items to cache.

src/jquery-1.6.2.min.js
src/jstorage.min.js
src/jquery.numeric.js
src/jquery.format-1.1.min.js
assets/json2.min.js
assets/jquery.signaturepad.css
assets/jquery.signaturepad.min.js
jquery.mobile-1.0b2/jquery.mobile-1.0b2.min.css
jquery.mobile-1.0b2/jquery.mobile-1.0b2.min.js
jquery.mobile-1.0b2/images/ajax-loader.png
jquery.mobile-1.0b2/images/icon-search-black.png
jquery.mobile-1.0b2/images/icons-18-black.png
jquery.mobile-1.0b2/images/icons-18-white.png
jquery.mobile-1.0b2/images/icons-36-black.png
jquery.mobile-1.0b2/images/icons-36-white.png
src/link-1-3.js
src/events-1-3.js
src/custom-styles.css
Login.html
把梦留给海 2024-10-11 06:28:59

默认情况下,jquery 的 ajax 函数将接收它接收的数据(json 和 jsonp 除外)。您可以使用以下命令告诉 ajax 调用不要缓存:

$.ajax({
  cache: false
})

by default jquery's ajax functions will the data it receives (except for json & jsonp). You can tell the ajax call not to cache using the following:

$.ajax({
  cache: false
})
允世 2024-10-11 06:28:59

IE 中的以下代码进行服务器调用,因为您正在缓存它而不进行后续调用...

if(navigator.appName == "Microsoft Internet Explorer") {
      http = new ActiveXObject("Microsoft.XMLHTTP");

The below code in IE makes a server call , as you are caching its not making subsequent calls...

if(navigator.appName == "Microsoft Internet Explorer") {
      http = new ActiveXObject("Microsoft.XMLHTTP");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文