weixin_33674437 2017-01-09 10:24 采纳率: 0%
浏览 23

jQuery AJAX错误警告

I have a CS:GO gamble site where user have to save his Steam Trade URL, i have made an JQuery AJAX post to save the data on database:

$(document).on('click', '#saveURL', function(e) {
    var data = $("#tradeURL").serialize();
    $.ajax({
        data: data,
        type: "post",
        url: "functions/tradeURL.php",
        success: function(data) {
            noty({
                text: '<b>Success!</b> <br>Your Trade URL is now saved.',
                layout: 'topRight',
                theme: 'metroui',
                type: 'success',
                maxVisible: 10,
                timeout: 5000,
                closeWith: ['click', 'timeout'],
                animation: {
                    open: {
                        height: 'toggle'
                    },
                    close: {
                        height: 'toggle'
                    },
                    easing: 'swing',
                    speed: 500 // opening & closing animation speed
                }
            });
        }
    });
});

If the data was submitted correctly it gives that alert, but my tradeURL.php contains this code:

if (isset($_REQUEST)) {
    $tradeURL = $_POST["tradeURL"];
    $tradeURL = htmlspecialchars(str_replace('', '', $tradeURL));
    $turl = explode("=", explode("&", "'.$tradeURL.'") [0]); // user trade url
    if ($turl[1] == $steamid - intval(0x0110000100000000)) {
        $update = "UPDATE users SET tlink='$tradeURL' WHERE steamid=$steamid";
        if ($db->query($update) === TRUE) {

            // THIS GIVES THE ALERT ON THE JQUERY SCRIPT

        }
        else {
            echo "Error updating record: " . $db->error;
        }
    }
    else {

        // HOW TO OUTPUT THIS ON THE AJAX POST ?

    }
}

So how i should make an alert to that part where it says // HOW TO OUTPUT THIS ON THE AJAX POST ? and it would save it to database.

  • 写回答

2条回答 默认 最新

  • ??yy 2017-01-09 10:35
    关注

    You can echo some value there:

    // HOW TO OUTPUT THIS ON THE AJAX POST ?
    echo "Invalid value."; // or your choice of text...
    

    Now in the success callback use this:

    success: function(data) {
        if(data === 'Invalid value.'){ // <--add this one
           alert(data);
           return;
        }
        noty({
            ...
        });
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装