为什么cache: false不能在jQuery AJAX中工作

why cache: false is not working in jQuery AJAX

本文关键字:jQuery AJAX 工作 不能 cache false 为什么      更新时间:2023-09-26

在我的示例中使用AJAX。在这里我使用了cache: false的性质。它总是触发请求(我勾选了网络选项卡)。为什么请求没有被缓存?这是我的代码

http://codepen.io/anon/pen/WGgKvd?编辑= 1010

$(function(){
    $('#btn').click(function(){
        alert('----')
        $.ajax({
            url: "https://api.github.com/events",
            data: {
                id: 123
            },
            cache: false,
            type: "GET",
            dataType : "json",
        }).done(function(json) {
            $("<h1>").text(json.title).appendTo("body");
            $("<div class='"content'">").html(json.html).appendTo("body");
        }).fail(function(xhr, status, errorThrown) {
            alert("Sorry, there was a problem!");
            console.log("Error: " + errorThrown);
            console.log("Status: " + status);
            console.dir(xhr);
        }).always(function(xhr, status) {
            alert("The request is complete!");
        });
    })
})

根据jQuery API,如果cache设置为false,将强制浏览器不缓存请求的页面。

我想你应该把它改成true