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 怎么获取下面的: glove_word2id.json和 glove_numpy.npy 这两个文件
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug