js如何获取缓存

js如何获取缓存,第1张

1、创建一个cachejs文件,前端页面,定义那些数据需要一次性拿到前端缓存,定义一个对象来保存这些数据。

2、前端页面,定义一个函数来调用后台接口获取数据,然后保存到本地缓存对象(dicts)中。

3、在主页面加载的时候调用这个方法一次性获取数据并缓存起来。这样,以后需要同样的数据,就直接从本地对象dicts中获取了。

4、后端Controller,定义一个接口,根据前端的请求,查询数据库(或查询服务器缓存,如下面例子中)获取数据返回给前端。

存到cookie中去,提交到数据库时从cookie中取出来传回服务器

function fun()

{

var price = documentgetElementById('price')value;

var count = documentgetElementById('count')value;

documentgetElementById('total')value = countprice;

documentcookie="ctotal="+countprice;

}

使用cookie即可。

<!DOCTYPE HTML>

<html lang="en-US">

<head>

<meta charset="UTF-8">

<meta name="keywords" content="白菜编辑部">

<title>白菜编辑部</title>

<style type="text/css">

</style>

<script type="text/javascript">

    function readCookie (name)

    {

        var cookieValue = "";

        var search = name + "=";

        if (documentcookielength > 0)

        {

            offset = documentcookieindexOf (search);

            if (offset != -1)

            {

                offset += searchlength;

                end = documentcookieindexOf (";", offset);

                if (end == -1)

                    end = documentcookielength;

                cookieValue = unescape (documentcookiesubstring (offset, end))

            }

        }

        return cookieValue;

    }

    function writeCookie (name, value, hours)

    {

        var expire = "";

        if (hours != null)

        {

            expire = new Date ((new Date ())getTime () + hours  3600000);

            expire = "; expires=" + expiretoGMTString ();

        }

        documentcookie = name + "=" + escape (value) + expire;

    }

     

    writeCookie ("myCookie", "my name", 24);

    alert (readCookie ("myCookie"));

</script>

</head>

<body>

</body>

</html>

以上就是关于js如何获取缓存全部的内容,包括:js如何获取缓存、js获取文本框的值并计算后,如何取得这个值保存在变量里,例如 int price=。。。、原生js如何保存一个小数据到数据库里等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/9789038.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-02
下一篇 2023-05-02

发表评论

登录后才能评论

评论列表(0条)

保存