Solution to the problem of net::ERR_CONNECTION_REFUSED

In one test, an error requesting background datagram net::ERR_CONNECTION_REFUSED. My specific failure this time is because the request address is wrong. There are many reasons for this problem, it may also be network reasons, etc... The most fundamental reason for this error is that the ajax request fails;

When I tested the login function at that time, the response on the page was that after clicking login, there was no response, and the user experience was very bad.

In the face of this situation, if a further judgment is made when the ajax request is made, and a failure prompt is given when the ajax request is unsuccessful, the experience will be better.

The specific optimization code is as follows:

The first is to monitor failed ajax requests globally. The disadvantage is that there is no event specificity, which may bring bad results.

$(document).ajaxError(function(){
        alert("请求出错!");
    });

The second: make a corresponding success or failure judgment for a single ajax request

$.ajax({
                url:"system/login/login.action",
                timeout:6000,
                success:function(data){}
         }).done().fail(function(){
                alert('网络不行,请求错误')
            })

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325857403&siteId=291194637