doudong0425 2017-04-21 06:12
浏览 27
已采纳

为什么在成功通话时未显示我的警报

I am trying to work out why my alert in the 'function processResponse(data)' part of the code, is not being displayed. I have tried various return; options, but still, refuses to display.

I would be grateful if someone could point out my error. Many thanks.

PS. I am aware of security issues in the code posted such as mysql_escape_string, but all security issues will be inserted before the site goes live.

jQuery code

<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 backend

    <?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, '"');

    }


        ?>
  • 写回答

1条回答 默认 最新

  • dongshou1991 2017-04-21 06:33
    关注

    The data value is not equal to true because of extra space to get rid of extra use .trim()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?