简体   繁体   English

如何防止 API 调用超时

[英]How can I prevent a API call from being timed out

Im trying to call my Backend API using jquery, and I did set the timeout to a very high amount but my request keeps stopping after sometime.我试图使用 jquery 调用我的后端 API,我确实将超时设置为非常高的值,但我的请求在一段时间后一直停止。 My API takes anywhere between 1 min to 7 mins to process the request but the API request keeps returning "We couldn't connect to our API, please check your network or contact support" when the API call takes more than 2 or 3 mins.我的 API 需要 1 到 7 分钟来处理请求,但是当 API 调用超过 2 或 3 分钟时,API 请求不断返回“我们无法连接到我们的 API,请检查您的网络或联系支持人员”。 Any code improvement and workaround would be greatly appreciated!任何代码改进和解决方法将不胜感激!

Here is my Code这是我的代码

function upgrade() {
$.ajaxSetup({
    timeout: 10000000 //Time in milliseconds
});
load();
$.getJSON("https://example.com", function(data) {
    if (data.success == true) {
        console.log("s");
    }
    else if (data.success == false) {
        console.log("f");
    }
    stopload();
})
.fail(function() { 
    console.log("We couldn't connect to our API, please check your network or contact support");
});}

A value of 0 means there will be no timeout.值为 0 表示不会超时。 Please try giving timeout as 0.请尝试将超时设置为 0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM