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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值