Set client timeout limit in chainGetJSON() (#2482)

By setting a client side timeout one can avoid net::ERR_NETWORK_IO_SUSPENDED errors caused by the OS network layer being suspended [1]. This allows the client to handle higher level errors.

The jQuery.getJSON() function does not have a parameter for timeouts.

[1]: https://cs.chromium.org/chromium/src/net/http/http_network_layer.cc?q=ERR_NETWORK_IO_SUSPENDED&sq=package:chromium&dr=C&l=42
This commit is contained in:
Albin Larsson 2020-04-06 10:42:38 +02:00 committed by GitHub
parent ded814220c
commit aac8359238
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -42,10 +42,15 @@ Ajax.chainGetJSON = function() {
var data = a[i++]; var data = a[i++];
var callback = a[i++]; var callback = a[i++];
$.getJSON(url, data, function(o) { $.ajax({
dataType: "json",
url: url,
data: data,
timeout: 30000
}).done(function(o) {
callback(o); callback(o);
next(); next();
}, "json"); });
} else if (i < a.length) { } else if (i < a.length) {
var finalCallback = a[i++]; var finalCallback = a[i++];
finalCallback(); finalCallback();