成功的Ajax帖子显示错误消息

时间:2013-09-11 14:08:23

标签: jquery ajax forms cross-domain zapier

我的表单通过POST使用Ajax正确提交数据。但是,我试图在成功提交后重定向用户。问题是,即使表单成功提交,而不是重定向用户它会显示错误。根据firebug我提交的页面,正在抛出200个成功代码。我正在使用jquery 1.8.3。

我的代码:

$(document).ready(function() {
$("#form4").submit(function(e) {
    e.preventDefault();
    var frm = $('#form4');
    $.ajax({
        type: 'POST',
        url: 'http://requestb.in',
        data: frm.serialize(),
        success : function() {
            window.location = "http://www.google.com";
        },
        /*error : function() {
            alert("Something went bad");
        }*/
    });
});

这是我的表单HTML:

<form action="" method="post" id="form4" name="form4" enctype="multipart/form-data">
    <input id="name" name="name" type="text" tabindex="1" value="Insert your name" class="required">
    <input id="email" name="email" type="text" tabindex="2" value="Insert your e-mail" class="required email">
    <input id="phone" name="phone" type="text" tabindex="3" value="Insert your phone number">
    <input type="submit" name="submit_button" value="Try it free">
</form>

为了找出确切的错误,我将以下代码添加到我的脚本顶部,我从此POST找到了:

$(function() {
    $.ajaxSetup({
        error: function(jqXHR, exception) {
            if (jqXHR.status === 0) {
                alert('Not connect.\n Verify Network.');
            } else if (jqXHR.status == 404) {
                alert('Requested page not found. [404]');
            } else if (jqXHR.status == 500) {
                alert('Internal Server Error [500].');
            } else if (exception === 'parsererror') {
                alert('Requested JSON parse failed.');
            } else if (exception === 'timeout') {
                alert('Time out error.');
            } else if (exception === 'abort') {
                alert('Ajax request aborted.');
            } else {
                alert('Uncaught Error.\n' + jqXHR.responseText);
            }
        }
    });
}); 

添加该代码后,我得到的以下错误来自第一个错误代码检查:'未连接。\ n验证网络。'。我测试了这是firefox和Chrome同样的结果。

修改:其他信息

我正在尝试将数据从我的网站发布到第三方表单处理器服务,该服务接受post,get和put命令。该服务是zapier.com,requestb.in是我用于解决表单提交问题的服务。

0 个答案:

没有答案
相关问题