In a test , Request background datagram net::ERR_CONNECTION_REFUSED
Error of . The reason why I failed this time is because of the wrong address . There are many reasons for this problem ,1, It could be the Internet 2, It is possible that the request address is wrong
…. The root cause of this mistake is that ajax request was aborted ;

The landing function test done at that time , The response on the page is after clicking login , There was no reaction , The user experience is very bad

In the face of this situation , If ajax Make another level of judgment when asking , stay ajax In case of unsuccessful request , Give failure prompt , The experience will be better

The specific optimization code is as follows :

The first one : Listen to the failed ajax request , The disadvantage is that there is no event specific , May bring bad effect

$(document).ajaxError(function(){
        alert(" Request error !");
    });

The second kind : For individual ajax Request a judgment of success or failure

$.ajax({
                url:"system/login/login.action",
                timeout:6000,
                success:function(data){}
         }).done().fail(function(){
                alert(' The Internet doesn't work , Request error ')
            })
 

Technology