对页面的更改不会保存(在页面重新加载时) [英] Changes to page are not saved (on page reload)

查看:194
本文介绍了对页面的更改不会保存(在页面重新加载时)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<div class='wrapper one Stone' id='main'>
<h1>Stone</h1>
<p>Price: $130.00 per Yard</p>
 <?php if($_SESSION[id]) {?> 
<button class="Stonebutton"> Delete Stone</button>
<script>; $(".Stonebutton").click(function(){$(".Stone").remove();}); </script> 
 <?php } ?> 
</div>

当im登录后,我可以看到删除石块按钮,当我点击它时,但当我重新加载页面时,它会回来。任何帮助?

When im logged in i can see the "Remove Stone" button and when i click it, it goes away but when i reload the page it comes back. Any help? Thanks a bunch!Im also loading this into the html page with a seperate php file using this:

fwrite($PlantFile, "\n\n<div class='wrapper one $trimmedname' id='main'>\n<h1>$name</h1>\n<p>Price: $price</p>\n <?php if(\$_SESSION[id]) {?> \n<button class=\"$trimmedbname\"> Delete $name</button>\n<script> \$(\".$trimmedbname\").click(function(){\$(\".$trimmedname\").remove();}); </script> \n <?php } ?> \n</div>\n");

fclose($PlantFile);

另外,如果任何人都有更好的解决方案,那么我该怎么做。感谢您的帮助!

Also if anyone has a better solution on what to do, im all ears. Thanks for all your help!

推荐答案

为了正确理解这一点,您需要了解网页的生命周期。

In order to properly understand this, you need to understand the life-cycle of a web page.


  1. 浏览器向服务器发出请求。

  2. 服务器响应该请求。从大量可能的响应中,我们将假定一切正常,并且它以网页(状态码: 200 )进行响应。大多数情况下(我们将在这里考虑的情况),响应是HTML。

  1. The browser makes a request to the server.
  2. The server responds to that request. From the large array of possible responses, we'll assume everything went OK and it responded with a web-page (status code: 200). Most times (and the case we will consider here), the response is HTML.

排除所有可能出错的事情, strong>服务器将始终为相同的请求返回相同的结果。但是,有时候,这还不够,这就是我们使用JavaScript的地方。使用JavaScript,我们可以对返回的HTML进行更改,而不必告诉服务器:创建一个包含此mod的新页面。

Excluding all the things that could go wrong, a server will always return the same result for the same request. However, sometimes, that's not enough and that's where we use JavaScript. With JavaScript, we can make changes to the returned HTML, without having to tell the server: create a new page, containing this mod.

。 remove()就是这样一种JavaScript方法。它在返回后更改HTML。它删除了作为初始响应一部分的HTML元素,而无需返回服务器并在请求期间首先删除生成元素的代码。

.remove() is such a JavaScript method. It changes the HTML after it was returned. It removes an HTML element that was part of the initial response, without going back to server and removing the code that generated the element in the first place, during the request.

这意味着当你刷新页面时页面将再次包含该元素,因为你正在发出相同的请求(你回到步骤1)。

This means that the page will contain the element again when you refresh the page, because you're making the same request (you're back to step 1).

如果网站按照您期望的方式工作,任何人都可以打开控制台并用一行简单的代码删除整个网站:

If web worked the way you seem to expect it to, anyone could open up the console and delete the entire website with a simple line of code:

document.body.remove();

幸运的是,现在Web的工作方式如此。

Luckily, that's now how web works.

这篇关于对页面的更改不会保存(在页面重新加载时)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆