PHP执行在javascript中没有返回任何内容

时间:2016-04-03 17:07:33

标签: javascript php jquery html

在输入中提交一个值由于某种原因通过java脚本返回任何内容,我尝试调试代码,在js代码检查提交的文本是否只是数字之后,它调用js函数并将值发送到php文件,这里分别是他们的代码:

PHP

<?php
if (isset($_POST['value'])) {
//connection au serveur
    $code = $_POST['value'];
    $db = mysqli_connect("localhost", "root", "") or die('Could not connect to the database because: ' . mysqli_error($db));
    //Pointage vers la base de donnée désirée
    $mydb = mysqli_select_db($db, "phptest");
    //lancer la requete
    $result = mysqli_query($db, "SELECT serialsold FROM validserial WHERE serial='" . $_POST['value'] . "'");
    //chercher dans la table
    if ($row = mysqli_fetch_array($result)) {
        $solde = $row['serialsold'];
        if ($solde <= 0)
        {
            echo "NULL";
        }
        else
        {
            echo "<input id=\"search-form\" class=\"m-wrap\" type=\"text\" value=\"You can buy with: $solde \" readonly required />
                  <select name='currencydd' id='currencydd' onchange=\"compare(this)\">;
                    <option value='mad'>DH</option>;
                    <option value='usd'>$</option>;
                    <option value='eur'>€</option>;
                  </select>
                  <button class=\"btnsucc\"/>";
        }
    } else {
        echo '0';
    }
}

JS

var previous;
    $('#search-form').tooltip();
    //------------------------------------Buy Stuff----------------------
    $(function () {
        $('#searchbar').bind('submit', function () {
            var value = $('#search-form').val();
            if (!isNaN(value)) {
                $.post('search.php', {value: value}, function (data) { //it calls search.php here, yes the file exists
                    if (data == '0')
                    {
                        newTooltip = 'Your Code is Invalid, please try again !';
                        $('#search-form').attr('title', newTooltip).tooltip('fixTitle').tooltip('setContent').tooltip('show');
                        setTimeout(function(){
                            $('#search-form').tooltip('hide').tooltip('destroy');
                        }, 5000);
                        return false;
                    }
                    else if (data == 'NULL')
                    {
                        newTooltip = 'Your Code Has no debit value, please enter another code !';
                        $('#search-form').attr('title', newTooltip).tooltip('fixTitle').tooltip('setContent').tooltip('show');
                        setTimeout(function(){
                            $('#search-form').tooltip('hide').tooltip('destroy');
                        }, 15000);
                        return false;
                    }
                    else {
                        $("#searchdiv").html(data);
                        previous = 'mad';
                    }
                });
                return false; //immediatly returns this
            }
            else {
                newTooltip = 'Please enter numbers ONLY !';
                $('#search-form').attr('title', newTooltip).tooltip('fixTitle').tooltip('setContent').tooltip('show');
                setTimeout(function(){
                    $('#search-form').tooltip('hide').tooltip('destroy');
                }, 5000);
                return false;
            }
        });
    });

HTML reference&amp;元素

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script type="text/javascript" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<form id="searchbar" method="post">
<div id="searchdiv">
<input id="search-form" class="m-wrap" type="text" placeholder="Enter your AllBuy Code..." /><button type="submit" name="buy" class="btn blue">buy</button>
</div>
</form>

0 个答案:

没有答案