【发布时间】:2017-08-18 19:49:38
【问题描述】:
我有一个 PHP 页面,它从 MYSQL 数据库中获取数据并根据从数据库返回的行生成 HTML 内容。
我正在使用 AJAX、Jquery 和 PHP 单击按钮时在数据库中添加新行。添加新行后,我使用window.location.reload(true); 重新加载页面。但是当我单击按钮时,不会显示与新行对应的 HTML 元素。但是,如果我使用 F5 手动刷新页面,则会显示新添加的内容。
有人知道为什么会这样吗?
下面是我点击按钮时调用的函数。页面 increaseCount.php 更新数据库以增加参与者的数量。但是在我使用 F5 刷新页面之前,不会显示与新计数对应的 HTML 元素。
function increaseCountOfNewActor(characterName) {
var actorName = document.getElementById("txt_actor_"+characterName).value;
var actorImage = document.getElementById("img_actor_"+characterName).src;
$.ajax( {
url: "increaseCount.php",
method: "POST",
data: {
name: actorName,
image: actorImage,
character: characterName
},
success: function( data ) {
alert("Vote received");
}
} );
window.location.reload(true);
}
【问题讨论】:
-
比较苹果和苹果,而不是苹果和橙子...
window.location.reload(true);相当于ctrl+f5- 在我看来,使用window.location.reload更新页面内容是一种非常不寻常的方式 - 显示一些代码 -
你能显示一些代码吗?
-
我添加了一些代码。但这可能没有多大帮助。
-
你能试试
location.reload();吗? @TusharGarud -
试过了。还尝试了许多其他方式的 location.reload,但没有奏效。
标签: javascript php mysql ajax