zoukankan      html  css  js  c++  java
  • jQuery ajax Load关闭缓存的方法

    [导读] 在jQuery ajax Load关闭缓存的方法很简单,我们只要在$ ajaxSetup中把cache: false就楞以了,当然我们还可以使用一个随机参数来实例了。简单介绍load(url,data,function(response,status,xhr))参数 描述 u

    在jQuery ajax Load关闭缓存的方法很简单,我们只要在$.ajaxSetup中把cache: false就楞以了,当然我们还可以使用一个随机参数来实例了。

    简单介绍load(url,data,function(response,status,xhr))参数 描述 
    url 规定要将请求发送到哪个 URL。 
    data 可选。规定连同请求发送到服务器的数据。 
    function(response,status,xhr) 可选。规定当请求完成时运行的函数。

    额外的参数:

    •response - 包含来自请求的结果数据
    •status - 包含请求的状态("success", "notmodified", "error", "timeout" 或 "parsererror")
    •xhr - 包含 XMLHttpRequest 对象
     

    jQuery Load样本代码:

     代码如下 复制代码

    $(document).ready(function(){ 
      $("#labels").load("/blog/categories/labels.html"); 
      //在页面装载时,在ID为#labels的DOM元素里插入labels.html的内容。 
    });

    当我更新了labels.html以后,在IE7里load方法仍旧在使用旧的labels.html,就算我按刷新键也不管用。好在jQuery提供一个防止ajax使用缓存的方法,把下面的语句加在head的javascript文件里,就可以解决问题。

     代码如下 复制代码

    $.ajaxSetup ({ 
        cache: false //关闭AJAX相应的缓存 
    });

  • 相关阅读:
    Valid Palindrome
    Construct Binary Tree from Inorder and Postorder Traversal
    LeetCode: LRU Cache
    LeetCode: Max Points on a Line
    LeetCode: Evaluate Reverse Polish Notation
    LeetCode:Two Sum
    LeetCode: Binary Tree Postorder Traversal
    LeetCode:Binary Tree Maximum Path Sum
    iOS开发 入门学习总结(二)Objective-C 语法特性总结
    LeetCode: Minimum Depth of Binary Tree
  • 原文地址:https://www.cnblogs.com/Gbeniot/p/5168606.html
Copyright © 2011-2022 走看看