weixin_33691817 2018-03-08 05:50 采纳率: 0%
浏览 6

AJAX无法运作

I have been staring at this for literally two hours trying to fix it. Any help would be appreciated. For some reason the table isn't being loaded when the button is clicked.

Here's the relevant part of my head:

<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css" />
</head>

This is my table:

<div class="container">
    <div class="midtxt">
        <div id = "transactions-sav" style="margin-top: 0;">
            <h2>Most Recent Transactions</h2>
            <table>
                <thead>
                    <tr>
                        <th>Username</th>
                        <th>Amount</th>
                        <th>Time & Date</th>
                        <th>Account Type</th>
                    </tr>
                </thead>
                <tbody>
                    <div id="trans-div">
                    </div>
                </tbody>
              </table>
              <hr />
            </div>
        </div>
        <a class="btn light-blue waves-effect waves-light table-end" id="trans-more" style="margin-top: 35px;">Load More Transactions</a>
    </div>

This is my Ajax transmitter:

<script>
    $(document).ready(function() {
        let transCount = 20;
        $('#trans-more').on('click', function() {
            transCount += 20;
            console.log('click');
            console.log(transCount);
            $('#trans-div').load('includes/loadtranshistajax.inc.php', {transNewCount: transCount,user_id: <?php echo $_SESSION['user_id']; ?>}, function() {
                console.log('callback');
            });
        });
        console.log('test1');
    });
</script>

This is my PHP script for generating the table. It is worth noting that initialize() starts a session.:

   <?php
require_once 'dbc-stu.inc.php';
require_once 'initialize.inc.php';
require_once 'app/transactions/transhist.inc.php';
initialize();
initialize_secure();

//Import the count
$limit = $_POST['transNewCount'];
$userID = $_SESSION['user_id'];

$sql = "SELECT * FROM transactions WHERE trans_targetID ='$userID' ORDER BY trans_time DESC LIMIT $limit";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);

while ($row = mysqli_fetch_assoc($result)) {
    echo '<tr>';
    foreach ($row as $key => $value) {
        if ($key === 'trans_time') {
            $time = $value;
            date_default_timezone_set("America/Los_Angeles");
            $time = date("F j, Y, g:i a",$time);
        } elseif ($key === 'trans_amount') {
            $amnt = $value;
        } elseif ($key ==='trans_targetID') {
            $username = idToUsername($value);
        } elseif ($key === 'trans_accType') {
            $accType = $value;
        }
    }
    echo '<td>' . $username . '</td>';
    echo '<td>' . $amnt . '</td>';
    echo '<td>' . $time . '</td>';
    echo '<td>' . $accType . '</td>';
    echo '</tr>';
}

Edit, thanks a lot everybody. I'm fairly new to the web development community, so it's cool to see everyone help out!

  • 写回答

2条回答 默认 最新

  • perhaps? 2018-03-08 06:08
    关注

    Remove div tag from tag and add id in tbody attribute as below.

     <tbody id="trans-div"></tbody>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求指导ADS低噪放设计
  • ¥15 CARSIM前车变道设置
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存