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()

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

报告相同问题?

悬赏问题

  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格