$.ajax statusCode

后端 未结 3 1303
萌比男神i
萌比男神i 2021-02-11 05:20

I have a problem in my code . This is part of it:

 function checkIfAvailable(username){
 var url = \"/checkAvail?user=\"+username;
 var ans =  $.ajax({
      url         


        
3条回答
  •  死守一世寂寞
    2021-02-11 05:30

    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);
            }
        });
    }
    

提交回复
热议问题