ajax 与 err_connection_refused,javascript - jQuery $.ajax, where to catch ERR_CONNECTION_REFUSED? - S...

I wrote the function below in order to send multiple get requests.

$( document ).ajaxError(function( event, jqxhr, settings, thrownError ) {

console.log('error2: ', event, jqxhr, settings, thrownError);

});

async function test1(){

cmds = [];

/*

cmds.push('function=PreviewInput&input=1');

cmds.push('function=Transition1');

cmds.push('function=PreviewInput&input=2');

cmds.push('function=Transition1');

cmds.push('function=PreviewInput&input=3');

cmds.push('function=Transition1');

cmds.push('function=PreviewInput&input=4');

*/

cmds.push('function=Transition1');

let url = "https://localhost:8088/api/?";

for(let [index, item] of cmds.entries()){

let GETPromise = new Promise(function(GETResolve, GETReject){

console.log(url + item);

//$.ajax({ url: url + item, error: myError })

$.ajax(url + item)

.done(function(data, textStatus, xhr){

GETResolve(xhr.status);

})

.fail(function(data, textStatus, xhr){

GETReject(xhr.status);

});

});

let result = await GETPromise

.then(response => { console.log('resolve: ' + index + ': ' + response)})

.catch(error => {console.log('reject: ' + index + ': ' + error)});

}

}

It works when the web server is up, then I tried to turn it off and I get ERR_CONNECTION_REFUSED.

This is what I see in the console:

https://localhost:8088/api/?function=Transition1

(index):89

error2: jQuery.Event {type: "ajaxError", timeStamp: 1607378314827, jQuery35104408785891773037: true, isTrigger: 3, namespace: "", …} {readyState: 0, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, …} {url: "https://localhost:8088/api/?function=Transition1", type: "GET", isLocal: false, global: true, processData: true, …}

(index):121

reject: 0: undefined

jquery.js:10099 GET https://localhost:8088/api/?function=Transition1 net::ERR_CONNECTION_REFUSED

send @ jquery.js:10099

ajax @ jquery.js:9682

(anonymous) @ (index):111

test1 @ (index):108

onclick @ (index):43

I added the $.ajax().fail() and $(document).ajaxError() callbacks to manage the error, and in fact they are both executed, but I keep getting the ERR_CONNECTION_REFUSED.

Where is the problem?

Using

jQuery 3.5.1 -

Getting same behavior with:

Chrome 87.0.4280.88 (official build) (64 bit),

Edge 87.0.664.52 (official build) (64 bit)