简体   繁体   English

成功刷新页面

[英]refresh page on success

I'm using the javascript code below to load recrefresh.php when the page initially loads. 当页面最初加载时,我正在使用下面的javascript代码加载recrefresh.php。 When the function ajaxvote is executed I want the following div to refresh: 执行ajaxvote函数时,我希望以下div刷新:

<div class="recrefresh"></div>

I tried adding the following after success:, but the div doesn't refresh after executing ajaxvote: 我尝试在成功之后添加以下内容:,但是执行ajaxvote后div不会刷新:

$.get('recrefresh.php', function(data) {
  $('.recrefresh').html(data);
});

Entire Script: 整个脚本:

<div class="recrefresh"></div>

<script type="text/javascript">
$.get('recrefresh.php', function(data) {
  $('.recrefresh').html(data);
});
</script>

<script>
$('.ajaxvote').click(function(e){
e.preventDefault(); // Prevents default link action
$.ajax({
 url: $(this).attr('href'),
 success: function(data){
alert("Vote Saved.");
$.get('recrefresh.php', function(data) {
  $('.recrefresh').html(data);
});

 }
});
});
  </script>

use this 用这个

<script>
$(document).ready(function(){
  //run function here
  refreshMyDiv();

  //click event for dynamically generated elements
  $('.recrefresh').on('click' , '.ajaxvote' , function(){
     //run function inside click
     refreshMyDiv();
  });
});

// function to refresh the .recrefresh div
function refreshMyDiv(){
  $.get('recrefresh.php', function(data) {
    $('.recrefresh').html(data);
  });
}
  </script>

To solve this issue take parent div to <div class="recrefresh"></div> because direct div does not load sometimes so wrap this div with other div say for ex. 要解决此问题,请将父div <div class="recrefresh"></div>因为有时直接div不会加载,因此请将该div与其他div一起包装,例如ex。

<div class="recrefresh_parent"><div class="recrefresh"></div></div>

and use recrefresh_parent to refresh table. 并使用recrefresh_parent刷新表。 There is the way to refresh or load div after ajax call: 有一种在ajax调用后刷新或加载div的方法:

$('.recrefresh_parent').load("recrefresh.php .recrefresh_parent");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM