Reputation: 53
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.
Upvotes: 1
Views: 1141
Reputation: 28767
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.
#cmd
div.There are other ways. All these ways try to pass the state ("page already loaded once") to the next load.
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?
Upvotes: 2
Reputation: 33865
There is no good way to detect if it was a page load or reload, it is basically the same thing. If you want to hide the element both when the page is first loaded, and then on every reload, you could do something like this:
$("#cmd").hide();
If it have to be on reload only, I guess one way would be to not use window.location.reload
but window.location.href
instead, and add something to the URL, like a querystring variable, that you then can check for on each page load, and hide the element if present.
Upvotes: 2