douying0108 2012-10-07 08:18
浏览 73

jquery - 重新加载后隐藏

I have this jquery code and every things working fine but after window.location.reload(true); I want to hide the div #cmd if possible

$(document).ready(function () {
    $("#add").click(
        function () {

            var id = $(this).attr("rel"); // ID
            var full_name = $("#full_name").val();
            var email = $("#email").val();
            var comments = $("#comments").val();
            var datapost = "id=" + id + "&full_name=" + full_name + "&email=" + email + "&comments=" + comments;

            $.ajax(
                {

                    type:"post",
                    url:"{/literal}{base_url()}{literal}post/add_cmd",
                    data:datapost,
                    success:function (Response) {
                        if (Response == 'added') {

                            alert("شكرا لك .. " + full_name + " على التعليق سوف يتم إداراج تعليقك بعد تحديث الصفحة");
                            window.location.reload(true);
                            $("#cmd").hide("Slow");

                        } else {
                            alert(Response);
                        }
// window.location.href = '../admcat/cats';
                    },
                    fail:function () {
                        alert("تعذر حذف الركورد لسوء الاتصال بالانترنت");
                    }
                }
            );


        }
    );


});

I want after window.location.reload(true); will hide the $("#cmd") if possible.

  • 写回答

2条回答 默认 最新

  • dsuxcxqep31023992 2012-10-07 08:27
    关注

    This is not so easy, because HTTP is a stateless protocol. That means, if you reload, the state of the page got lost.

    But there's a way when you use JavaScript and PHP together.

    1. Set a cookie on the first load
    2. On the reload in PHP check existence of the cookie and set visibility of the #cmd div.

    There are other ways. All these ways try to pass the state ("page already loaded once") to the next load.

    1. Reload using a different method (first time GET, then POST)
    2. Pass an URL parameter instead of just reloading
    3. Use PHP session

    All these four ways need PHP to check: Does the cookie exist, what's the HTTP method, what's the parameter, what's in the session?

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么