<div id='mydiv'>
<a href="update.php" target="_blank" onClick="return openWindowReload(this)">update</a>
</div>
<script>
function openWindowReload(link) {
setTimeout(function(){
var href = link.href;
window.open(href,'_blank');
document.location.reload(true)
}, 5000);
return false;
}
</script>
所以我有这段代码,在单击“更新”按钮(target =“_blank”)后强制刷新(5秒后)当前页面...
但我只想重新加载特定的 div....
说明:
更新按钮仅在表中的字段更新 = false 时可见...所以当它为 true 时更新按钮不可见..但是当您单击按钮更新时它将首先更新表并设置更新 = true
更新.php
<?php
mysqli_query($con, 'UPDATE TABLE sET updating = TRUE');
(long code in here)
?>
那么你们能帮助我实现我的目标吗......
最佳答案
使用 jquery $.post 简写 ( http://api.jquery.com/jquery.post/ ),例如:
$(document).ready(function(){
$.post( "update.php", function( data ) {
// wrap this with the timeout, if you need
// but the method post is asynchronous already and takes time
$( ".update" ).hide();
});
});
HTML:
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<button class="update">Update!</button>
</body>
</html>
仅此而已!希望这有帮助!
关于javascript - 单击链接后刷新 div _blank,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23690858/