Is there any analog to a 'finally' in jQuery AJAX calls?

后端 未结 6 516
北荒
北荒 2021-02-04 22:45

Is there a Java \'finally\' analogue in jQuery AJAX calls? I have this code here. In my always I throw an exception, however I ALWAYS want it to go to the

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-04 23:35

    There is a bug ajax is dependent on the server, need to check status with "complete" is the best, a kind of "success", "error" and others are not 100% of the PUT, POST and GET ... look at an example

    $.ajax({
        url: '/api/v2/tickets/123456.json',
        ....
        ....
        ....
        complete: function(data) { 
            if (data.statusText == "success") { 
                console.log("Sent successfully");
            } else { 
                console.log("Not Sent");
            }
        }
    });
    

    Sorry bad english! Cheer ;-)

提交回复
热议问题