当ajax表单失败时,无法显示错误消息

时间:2017-05-20 00:40:16

标签: jquery ajax forms

我试图让我的表单优雅地失败,但是无论什么放在那里,都没有让错误功能完全起作用。一切正常,但如果我强制错误(例如,给出错误的var名称),我在控制台中看到错误,但我的警报没有触发。

这是我的代码:

$.ajax({
    async: false,
    cache: false,
    type: 'post',

    url: 'dostuff/234',

    data: {
        email: fEmail,
        firstname: fFirstname,
        lastname: fLastname,
        zipcode: fZipcode,
        optout: fOptout
    },
    dataType: "text",
    error: function(xhr, status, error) {
        alert(status);
        alert(xhr.responseText);
    },  
    success: function (response) {
        overlay.appendTo(document.body);
        setTimeout(function(){ finishUp(); }, 3000);    
    }
});

1 个答案:

答案 0 :(得分:0)

如果定义正确,您应该能够获得错误消息或成功。

-Wunsequenced



-Wall

  data: {
        email: "fEmail",
        firstname: "fFirstname",
        lastname: "fLastname",
        zipcode: "fZipcode",
        optout: "fOptout"
  },