0

提交以下 $.ajax,它确实正在执行,但无提示地失败,没有任何错误。IE9 开发工具不会弹出错误,提琴手显示没有流量。

我可以确认代码确实执行了,因为屏幕上确实出现了“处理”位。然而,其余的似乎只是失败了。我不是在做 x 域。

$('.signupMsg').html("<img src='/assets/img/load-black.gif' /> Processing...");
var data = $('#emailForm').serialize();
$.ajax({
    url: 'https://example.com/proxy/emaillist',
    type: 'POST',
    data: data,
    statusCode: {
        200: function(msg) {
            $('.signupBlock').html("&nbsp;<br><strong>Thank you!</strong><br>You will be hearing from us soon.");
            $('#emailForm').remove();
        },
        500: function(msg) {
            $('.signupBlock').html("&nbsp;<br><strong>Something went wrong.</strong><br>Sorry about that, please <a href='/'>refresh</a> and try again.");
            $('#emailForm').remove();
        },
            404: function(msg) {
                    $('.signupBlock').html("&nbsp;<br><strong>Something went wrong.</strong><br>Sorry about that, please <a href='/'>refresh</a> and try again.");
                    $('#emailForm').remove();
            },
        503: function(msg) {
            $('.signupBlock').html("&nbsp;<br><strong>Server temporarily down.</strong><br>Sorry about that, please <a href='/'>refresh</a> and try again.");
            $('#emailForm').remove();
        },
        400: function(msg) {
            $('.signupMsg').html("<span style='color:red'>Email validation failed, please try again.</span>");
        }
    }                   

});

使用 jQ 1.7.2。该代码在 Google Chrome 中执行良好,但在 IE7-9 和 FF 中失败。旧浏览器不支持 statusCode 吗?

或者我应该切换到 SuperAgent 以获得代码响应支持?http://visionmedia.github.com/superagent/

4

1 回答 1

0

好吧,它不是针对 jQuery 的修复,而是针对 AJAX 调用的修复。

我刚刚切换到 SuperAgent 并得到了同样的工作:

request
.post('url/to/example')
.send(data)
.end(function(res){
    if(res.status==200) {
        $('.signupBlock').html("&nbsp;<br><strong>Thank you!</strong><br>You will be hearing from us soon.");
        $('#emailForm').remove();                           
    }
    if(res.status==500) {
        $('.signupBlock').html("&nbsp;<br><strong>Something went wrong.</strong><br>Sorry about that, please <a href='/'>refresh</a> and try again.");
        $('#emailForm').remove();
    }
    if(res.status==404) {
        $('.signupBlock').html("&nbsp;<br><strong>Something went wrong.</strong><br>Sorry about that, please <a href='/'>refresh</a> and try again.");
        $('#emailForm').remove();
    }
    if(res.status==503) {
        $('.signupBlock').html("&nbsp;<br><strong>Server temporarily down.</strong><br>Sorry about that, please <a href='/'>refresh</a> and try again.");
        $('#emailForm').remove();
    }
    if(res.status==400) {
        $('.signupMsg').html("<span style='color:red'>Email validation failed, please try again.</span>");
    }
});
于 2012-06-29T01:33:28.320 回答