weixin_33726318 2017-11-28 04:53 采纳率: 0%
浏览 56

jQuery Ajax错误不起作用

jQuery:

$.ajax({
    method: "POST",
    url: formsubmission,
    data: data,
    success: function() {
        alert("E-mail Sent");
        $("#submit").replaceWith('<button type="button" class="btn btn-primary" id="submit" onclick="send_email()">Submit</button>')
    }
    Error: function() {
        alert("E-mail Fail");
        $("#submit").replaceWith('<button type="button" class="btn btn-danger" id="submit" onclick="send_email()">Submit</button>')
    }
})

Anyone can please tell me Why Error function is not working? How can I resolve it?

  • 写回答

1条回答 默认 最新

  • 10.24 2017-11-28 06:13
    关注

    Change your code into this and check if you still have problem triggering the error function of your ajax call, and also instead of replacing the whole element in your error function, I removed the 'btn-primary' class and added 'btn-danger' class to make it shorter.

    $.ajax({
        method: "POST",
        url: formsubmission,
        data: data,
        success: function() {
            alert("E-mail Sent");
            $("#submit").replaceWith('<button type="button" class="btn btn-primary" id="submit" onclick="send_email()">Submit</button>')
        },
        error: function() {
            alert("E-mail Fail");
            $("#submit").removeClass('btn-primary').addClass('btn-danger');
        }
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序