How to check the Code status of an ajax request

Asked

Viewed 286 times

1

I have a very simple AJAX request. But I wonder if you can read the status code returned within the method done. More or less like below:

$('#form-aluno').submit(() => {
    let data = $('#form-aluno').serialize();


    const register = $.ajax({
        method: "post",
        url: "/alunos/register/save",
        dataType: "json",
        data: data
    })

    register.done((e) => {
        console.log(e.statusCode) //tem como fazer algo do tipo ou similar ?
    })


    return false;
})

1 answer

2

I was able to solve the problem in question. I’ll leave the answer here in case anyone has any doubts

solved using the third callback parameter of the ajax done function as below:

register.done((e, status, code) => {
    console.log(code.status)
})
  • Ajax implements so Xmlhttprequest. See here to use this simply and read the codes. https://www.w3schools.com/js/js_ajax_http.asp

Browser other questions tagged

You are not signed in. Login or sign up in order to post.