Q:

$.ajax statusCode

I have a problem in my code . This is part of it:
 function checkIfAvailable(username){
 var url = "/checkAvail?user="+username;
 var ans =  $.ajax({
      url: url,
      type: "GET",
      context: document.body,
      statusCode: {
        404: function() {
          console.log("-1-1-1-1 WE GOT 404!");
        },
        200: function() {
          console.log("-1-1-1-1 WE GOT 404!");
        }
      }
    });
         }

I think the response.status is 200, but I don't enter the '200' part.
So how can I print the response.status I'm getting?

A:

success(data, textStatus, jqXHR){
    var statusCode = jqXHR.status;
    var statusText = jqXHR.statusText;
}

See jQuery API for more options...

A:

function checkIfAvailable(username) {
    var ans = $.ajax({
        url: "/checkAvail",
        type: "GET",
        data: "user=" + username,
        dataType: "html",//change it by the data type you get (XML...)
        context: document.body,
        statusCode: {
            404: function() {
                console.log("-1-1-1-1 WE GOT 404!");
            },
            200: function() {
                console.log("-1-1-1-1 WE GOT 200!");
            }
        },
        success: function() {
            console.log("success");
        },
        error: function(e) {
            alert(e);
        }
    });
}

