dongmei6426 2016-09-27 09:15
浏览 12

Ajax形式超时

I have a PHP page with form with 100s of fields in it. I'm using Ajax to fetch content to each field upon typing in the data.

Sometimes, it happens that I get this error:

net::ERR_CONNECTION_TIMED_OUT

Presumably because the server fails to respond on time. When that happens, there is an error and Ajax won't work further.

Is there a way I can make the code execute even after the error? So that I can continue trying Ajax again?

Note: I'm using plain old XMLHttpRequest() request, not jquery functions

  • 写回答

2条回答 默认 最新

  • doushi6932 2016-09-27 09:18
    关注

    In your ajax code try to define the timeout settings to 0 (unlimited):

    $.ajax({
    timeout: 0, //Set your timeout value in milliseconds or 0 for unlimited
    

    You can set this value to 3 seconds (3000) and catch the exception with the error function. Like this:

    error: function(jqXHR, textError, errorThrown) {
        if(textError==="timeout") {  
            alert("Call has timed out"); //Handle the timeout
        } else {
            alert("Unknown error"); //Handle other error type
        }
    

    Hope that will help

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line