javascript - 单击链接后刷新 div _blank

标签 javascript php jquery

<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/

相关文章:

javascript - Protractor : Issue with using executescript to execute javascript on an element

javascript - 为什么<a>标签用%2520替换空格?如何解决问题?

php - 如何按值数据对多数组进行排序?

php - 如何在使用 Zend_File_Transfer_Adapter_Http() 上传时调整图像大小;

javascript - 检测异步调用完成,然后触发另一个函数?

java - 浏览器尝试保存对 AJAX 请求的 JSON 响应而不是处理它

javascript - 如何获取 JSON POST 的结果

javascript - Sprite 动画Javascript?

php - PHP 是否有 "named parameters"以便可以省略前面的参数并可以写入后面的参数?

javascript - 使用 jQuery 的 <div> 内带有 <select> 的菜单