【问题标题】:Cached Pages AJAX Not Working缓存页面 AJAX 不工作
【发布时间】:2010-11-24 02:40:18
【问题描述】:

当一个页面在 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){

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

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

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

【问题讨论】:

  • 我不这么认为,只有服务器到服务器的调用不会第二次进行,客户端到服务器的调用应该可以工作。你在做页面级缓存吗
  • 您能否提供更多详细信息,例如您的 ajax 代码调用后端。
  • 欢迎使用stackoverflow

标签: jquery ajax caching manifest jqtouch


【解决方案1】:

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

【讨论】:

  • 我该如何明确要求?
  • @precurson ,调用代码是什么,javascript或服务器端代码...如果是javascript,您可以打开firebug,.net面板并查看结果。
  • 我不明白,您是在使用 jquery 还是在编写自己的 XMLHTTP 调用?
  • 通常是 JQuery,我只使用 XMLHTTP 来调试问题,因为我对它比较熟悉。到目前为止,我一直没有成功
【解决方案2】:

我一直在尝试让 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

【讨论】:

  • 我的 AJAX URL 采用 MVC 格式:http://host/Controller/Action/ 指定 /Action//Action/Action/* 不起作用。还有什么我可以尝试的吗?
【解决方案3】:

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

$.ajax({
  cache: false
})

【讨论】:

  • 我从来没有在我的任何代码中提到缓存 false ,但它总是会调用。??任何输入
  • 这不起作用,因为问题是应用程序缓存,而不是常规浏览器缓存。您的建议解决了浏览器缓存问题。
【解决方案4】:

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

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

【讨论】:

    猜你喜欢
    • 2011-11-19
    • 2012-03-19
    • 2018-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-04
    • 2014-02-18
    • 1970-01-01
    相关资源
    最近更新 更多