单击时如何存储和检索按钮的值?

时间:2016-11-30 02:28:25

标签: javascript mysql

我为我的足球队制作了一个签到应用程序。我认为我已经正确编程了按钮,但是我在存储值和从mySQL数据库中检索值时遇到了问题。有人可以告诉我我错过了哪些代码吗?提前谢谢。

<style>
    .height {
        height: 100px;
    }

    .height2 {
        height: 50px;
        text-align: center;
    }

    .fc {
        display: block;
        margin-left: auto;
        margin-right: auto;
    }

    body {
        font-family: monospace;
        font-size: 4em;
        font-weight: bold;
    }

    .btn-xl {
        padding: 15px 24px;
        font-size: 24px;
        line-height: 1.4;
        border-radius: 8px;
        text-transform: uppercase;
    }
</style>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
    (function($, window, document) {
        $(function() {
            // bind to the click event of the checkin button
            $('.btn-player-checkin').on('click', function() {
                // if the button has the success class - assume the user is checked in
                var isCheckedIn = $(this).hasClass('btn-success');
                // get the player id from the data attribute
                var playerId = $(this).data('player-id');


                // call the send function
                // sendDataToServer(!isCheckedIn, playerId, $(this)); // send the status we want the player to save (ie. opposite of current);

                // if you would like to test the success function without the ajax call, comment out above and uncomment below
                if (!isCheckedIn) { // trying to check out
                    $(this).text('IN');
                } else { // checking in
                    $(this).text('OUT');
                }
                // cycle classes
                $(this).toggleClass('btn-success btn-danger');

            });

            function sendDataToServer(newStatus, playerId, button) {
                $.ajax({
                    url: 'http://labombafootball.com/checkin', // replace this with the url of the server end point
                    method: 'POST',
                    data: {
                        playerId: playerId,
                        status: newStatus
                    } // send this data, on the server you could also record the timestamp of when this occurred
                }).done(function() { // if we successfully complete the post
                    if (newStatus) { // checking in
                        button.text('OUT');
                    } else { // trying to check out
                        button.text('IN');
                    }
                    // cycle classes
                    button.toggleClass('btn-success btn-danger');
                }).fail(function() {
                    // do something if the post fails
                });
            }
        });
    }(window.jQuery, window, document));
</script>

<body>
<div class="container-fluid">
    <div class="row">
        <div class="col-xs-12 height"><img class="fc" src="images/la-bomba-fc-sm.jpg"></div>
    </div>

    <div class="row">
        <div class="col-xs-8 height2">#2 STEVE B</div>
        <div class="col-xs-4">
            <button class="btn btn-danger btn-xl btn-player-checkin" data-player-id="2">OUT</button>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-xs-8 height2">#1 INDER JHOOTY</div>
        <div class="col-xs-4">
            <button class="btn btn-danger btn-xl btn-player-checkin" data-player-id="1">OUT</button>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-xs-8 height2">#21 CHRIS NAKATSU</div>
        <div class="col-xs-4">
            <button class="btn btn-danger btn-xl btn-player-checkin" data-player-id="21">OUT</button>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-xs-8 height2">#88 NICK MARSHALL</div>
        <div class="col-xs-4">
            <button class="btn btn-danger btn-xl btn-player-checkin" data-player-id="88">OUT</button>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-xs-8 height2">#99 TONY YUN</div>
        <div class="col-xs-4">
            <button class="btn btn-danger btn-xl btn-player-checkin" data-player-id="99">OUT</button>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-xs-8 height2">#6 DANIELE BORRELLI</div>
        <div class="col-xs-4">
            <button class="btn btn-danger btn-xl btn-player-checkin" data-player-id="6">OUT</button>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-xs-8 height2">#11 NITESH SHETTY</div>
        <div class="col-xs-4">
            <button class="btn btn-danger btn-xl btn-player-checkin" data-player-id="11">OUT</button>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-xs-8 height2">#45 UDAYA MADANAYAKE</div>
        <div class="col-xs-4">
            <button class="btn btn-danger btn-xl btn-player-checkin" data-player-id="45">OUT</button>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-xs-8 height2">#9 ADRIAN PARTYKA</div>
        <div class="col-xs-4">
            <button class="btn btn-danger btn-xl btn-player-checkin" data-player-id="9">OUT</button>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-xs-8 height2">#5 PATRICK REGAN</div>
        <div class="col-xs-4">
            <button class="btn btn-danger btn-xl btn-player-checkin" data-player-id="5">OUT</button>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-xs-8 height2">#13 RAMEZ ALAM</div>
        <div class="col-xs-4">
            <button class="btn btn-danger btn-xl btn-player-checkin" data-player-id="13">OUT</button>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-xs-8 height2">#8 FAIZAN ALAM</div>
        <div class="col-xs-4">
            <button class="btn btn-danger btn-xl btn-player-checkin" data-player-id="8">OUT</button>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-xs-8 height2">#33 DAVID CLEBAN</div>
        <div class="col-xs-4">
            <button class="btn btn-danger btn-xl btn-player-checkin" data-player-id="33">OUT</button>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-xs-8 height2">#14 VICTOR JIMENEZ</div>
        <div class="col-xs-4">
            <button class="btn btn-danger btn-xl btn-player-checkin" data-player-id="14">OUT</button>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-xs-8 height2">#7 HARRY SANDHU</div>
        <div class="col-xs-4">
            <button class="btn btn-danger btn-xl btn-player-checkin" data-player-id="7">OUT</button>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-xs-8 height2">#77 JOHN PINEDA</div>
        <div class="col-xs-4">
            <button class="btn btn-danger btn-xl btn-player-checkin" data-player-id="77">OUT</button>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-xs-8 height2">#44 DEVON CARNEY</div>
        <div class="col-xs-4">
            <button class="btn btn-danger btn-xl btn-player-checkin" data-player-id="44">OUT</button>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-xs-8 height2">#17 JUSTIN CONSTANTINEAU</div>
        <div class="col-xs-4">
            <button class="btn btn-danger btn-xl btn-player-checkin" data-player-id="17">OUT</button>
        </div>
    </div>
</div>

0 个答案:

没有答案