Any way to gracefully enforce a timeout limit when loading a slow external file via javascript?

前端 未结 4 850
余生分开走
余生分开走 2020-12-17 18:15

I\'m using javascript to include some content served up from a php file on another server. However, this other service can sometimes get flaky and either take a long time t

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-17 18:43

    I think that the only way to do this is take the content of the file via ajax and then set a timer. If the request finishes before the timer you can evaluate the respons with eval(that's not the better solution anyway), otherwise you can stop the ajax request and write the error message.

提交回复
热议问题