javascript - jQuery handle Ajax timeout? - Stack Overflow

I'm trying to catch Ajax timeout error with jQuery 1.4.2, but none of tutorial I found work. In Fi

I'm trying to catch Ajax timeout error with jQuery 1.4.2, but none of tutorial I found work. In Firebug, when timeout error fires. I see:

uncaught exception: [object Object].

Please help me handle Ajax timeout. Here's my JS code:

$.ajax({
    type:"POST",
    url:"/data/add/",
    data:
    {
    "date":$("input#date").val();
    },
    dataType:"json",
    timeout:2000,
    success: function(response) {
    },
    error: function () {
        alert('Server error');
    }
});

I'm trying to catch Ajax timeout error with jQuery 1.4.2, but none of tutorial I found work. In Firebug, when timeout error fires. I see:

uncaught exception: [object Object].

Please help me handle Ajax timeout. Here's my JS code:

$.ajax({
    type:"POST",
    url:"/data/add/",
    data:
    {
    "date":$("input#date").val();
    },
    dataType:"json",
    timeout:2000,
    success: function(response) {
    },
    error: function () {
        alert('Server error');
    }
});
Share Improve this question edited Jul 12, 2021 at 18:41 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Aug 22, 2010 at 2:43 andymcgregorandymcgregor 1,0152 gold badges14 silver badges29 bronze badges 1
  • You have an errant semi-colon in your data option. See my answer below. – David Hoerster Commented Aug 22, 2010 at 3:35
Add a ment  | 

2 Answers 2

Reset to default 5

I tested this out, and if you remove the ; from your $("input#date").val() statement, it should work.

$.ajax({
    type:"POST",
    url:"/data/add/",
    data:
    {
    "date":$("input#date").val()
    },
    dataType:"json",
    timeout:2000,
    success: function(response) {
    },
    error: function () {
        alert('Server error');
    }
});

something went wrong again, and i got googled this f*****g bug http://dev.jquery./ticket/6173 ! here is the spike:

success: function(response, textStatus, xhr) {
    if (!xhr.status) {
        alert("ERROR!!!!");
    }
    else {
        // elided
    }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744888339a4599252.html

相关推荐

  • javascript - jQuery handle Ajax timeout? - Stack Overflow

    I'm trying to catch Ajax timeout error with jQuery 1.4.2, but none of tutorial I found work. In Fi

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信