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 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)