在刷新F5之前,运行AJAX代码时不会更新行总和 [英] sum of rows is not updated when running AJAX code until F5 refresh

查看:67
本文介绍了在刷新F5之前,运行AJAX代码时不会更新行总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下

Following this link here about sending data into MySQL using AJAX, I have this output:

我想要的是看到具有div所示而不是底部显示的当前行的行.以及如何刷新总和,而不是等待刷新页面?

What I want, is to see the row with the curent rows shown in the div and not at the bottom. And how to refresh the sum, and not wait to refresh the page ?

这是最终的AJAX代码:

Here is the final AJAX code:

function addFunction()
{
    var selectW = $('#insert_new').val();
    var selectW = $('#selectW').val();
    var select_at = $('#select_at').val();
    var pay = $('#pay').val();
    var facture = $('#facture').val();
    var select_opt = $('#select_opt').val();
    if(pay!="")
    {
        $.ajax({
            data: {'selectW': selectW, 'select_at': select_at, 'pay': pay, 'facture': facture, 'select_opt': select_opt},
            type: "post",
            url: "insert_buy.php",
            success: function(response){
                  if(response=="success")
                  {
                    $('#incident_table').append('<tr><td height="30" align="center">' + selectW + '</td><td align="center">' + select_at + '</td> <td align="center" dir="ltr">' + pay + '</td> <td align="center">' + facture + '</td> <td align="center"><form action="delete.php" method="post"><input type="hidden" name="rowid" value="" /><input class="imgClass_dell" type="submit" onclick="return confirm(\'هل أنت متأكد؟\')" name="delete_sales" value="" /></form></td></tr>');
                    alert(data);
                    $('#selectW').val('');
                    $('#select_at').val('');
                    $('#pay').val('');
                    $('#facture').val('');
                    $('#select_opt').val('');
                  }
                  else
                  {
                    alert("No Data added");

                  }
            },
            error: function(){
                //alert('error; ' + eval(error));
            }
        });
    }
    else
    {
        alert("All Fields Are Required!!");
    }

}

这是PHP计算总和的位置:

And here is where PHP calculate the sum:

      </tr>
      </form>   
      <?php
        $sum = 0;
        $selectAll = "SELECT * FROM sales WHERE date_now = :date ORDER BY date_now DESC, time_now DESC";
        $stmtAll=$conn->prepare($selectAll);
        $stmtAll->bindValue(':date', date("y-m-d"));
        $execAll=$stmtAll->execute();
        $result=$stmtAll->fetchAll();
      ?>
      <?php foreach($result as $rows){
          $sum = $sum + $rows['pay'];
          //var_Dump($rows) ?>
    <tr>
      <td height="30" align="center"><?php echo $rows['type'] ?></td>
      <td align="center"><?php echo $rows['provider'] ?></td>
      <td align="center" dir="ltr"><?php echo (number_format($rows['pay'], 0, ',', ' ')). ' L.L'?></td>
      <td align="center"><?php echo $rows['facture'] ?></td>
      <td align="center"><form action='delete.php' method="post">
          <input type="hidden" name="rowid" value="<?php echo $rows['id'] ?>" />
          <input class="imgClass_dell" type="submit" onclick="return confirm('هل أنت متأكد؟')" name="delete_sales" value="" />
        </form></td>
    </tr>
    <?php } ?>
    <tr>
    <th colspan="4" align="center" bgcolor="#666666">المجموع</th>
    <td dir="ltr" bgcolor="#666666" align="center"><?php
        echo ($sum = number_format($sum, 0, ',', ' ')). ' L.L';
      ?></td>
    </tr>
  </table>
</div>
</div>

希望我能得到一些帮助.

I hope I can get some help.

推荐答案

您可以尝试使用此

您将需要一个显示表的getTable.php页面,并且没有其他内容:没有页眉,页脚等.

You'll need a getTable.php page that displays your table, and nothing else: no headers, footers, etc.

PHP(getTable.php)-这可以是任何服务器端代码(asp,html等.)

PHP (getTable.php) - this can be any server side code (asp, html, etc..)

<?php
    echo '<table><tr><td>TEST</td></tr></table>';
?>

然后,在您的JS中,您可以使用load()方法轻松刷新表:

Then, in your JS, you can easily refresh the table by using the load() method:

HTML

<div id="tableHolder"></div>

js

<script type="text/javascript">
    $(document).ready(function(){
      refreshTable();
    });

    function refreshTable(){
        $('#tableHolder').load('getTable.php', function(){
           setTimeout(refreshTable, 5000);
        });
    }
</script>

尝试并祝你好运,我更喜欢与jqgrid合作

try and good luck i prefer work with jqgrid

这篇关于在刷新F5之前,运行AJAX代码时不会更新行总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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