繁体   English   中英

为什么我的警报未在成功呼叫中显示

[英]Why is my alert not being displayed on success call

我试图弄清为什么我的警报在代码的“ function processResponse(data)”部分中没有显示。 我尝试了各种回报; 选项,但仍然拒绝显示。

如果有人可以指出我的错误,我将不胜感激。 非常感谢。

PS。 我知道发布的代码中存在安全性问题,例如mysql_escape_string,但是所有安全性问题都会在网站上线之前插入。

jQuery代码

<script type="text/javascript">

$(function() {

    $('#srcsubmit').click(function(e) {
        e.preventDefault();
        if ($('#srcBox').val() == '') {

            notif({
                type: "error",
                msg: "<b>ERROR:<br /><br />You must enter a search term</b><p>Click anywhere to close</p>",
                height: 99,
                multiline: true,
                position: "middle,center",
                fade: true,
                timeout: 3000

            });
            return false;
        }

        $("#submit").prop("disabled", true);
        $("#submit2").prop("disabled", true);
        $("#submit3").prop("disabled", true);
        var value = $('#srcBox').val();
        var dept = '<?php echo $_GET['dept ']; ?>';

        var qString = 'sub=' + encodeURIComponent(value) + '&dept=' + encodeURIComponent(dept);

        $.post('sub_db_handler.php', qString, processResponse);
    });

    function processResponse(data) {
        if (data === 'true') {

            alert('That box is not on the system'); <--- this is the problem
            return;
        }

        $('#srcBoxRslt').val(data);
    };
});


</script>

PHP后端

    <?php session_start(); ?>
    <?php

    $con = mysql_connect("localhost","root","");
    if(!$con) { die('Could not connect: ' . mysql_error()); }
    mysql_select_db("sample", $con);

    $dept = trim($_POST['dept']);
    $custref = trim($_POST['sub']);



    $result = mysql_query("SELECT * FROM boxes WHERE custref = '".$custref."'");
    $found = mysql_num_rows($result);

     if ($found == 0)
        {
            echo trim('true');

        } else {

    $query = "SELECT * FROM boxes WHERE department = '".$dept."' AND status = 1 AND custref = '".$custref."'";
    $result = mysql_query($query) or die(mysql_error());
    $row = mysql_fetch_array($result) or die(mysql_error());
    $r = $row['custref'];

    $str =  json_encode($r);
    echo trim($str, '"');

    }


        ?>

数据值不等于true因为有多余的空间来消除多余的使用.trim()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM