开发者

For what server error code does the jquery ajax 'error' option stand for?

Can someone tell me for what server request code does the 'error' option in jquery ajax ($.ajax) stand for? Because I want to handle the 400 server error, but I can't seem to do it using that 'error' option. I don't know if I'm doing something wrong in my code or whether it's a bug... Please I need your assistance. Thank you.

var options = {
    type: "post",
    target: "#responsePanel",
    beforeSend: function(){
        $("#uploadingImg").show();
        $("#polygonUploadPanel, #polygonUploadBtnHolder").hide();
    },
    complete: function(){
        $("#uploadingImg").hide();
        $("#polygonUploadPanel, #polygonUploadBtnHolder").show();
    },
    success: function(response, statusString, xhr, $form){
        $("#responsePanel").html(statusString);
        //map.polygonUploaded();
        $("#polygonUploadForm").hide();
    },
    error: function(response, statusString, err){
        $("#responsePanel").html(statusString);
        $("#polygonUploadPanel, #polygonUploadBtnHolder").hide();
        $("#polygonUploadBtn").hide();
        $("#ajaxUploadError").show();
        $(".errorHeading a").click(function(e){
            if($(".errorDetails").is(":visible")){
                $(".errorDetails").hide();
            }
            else{
                $(".errorDetails").show();
            }
        });

        if(response.status == 400) {
             $("#polygonUploadForm").show();
  开发者_C百科      }

        if(response.status == 601) {
             sessionTimedOut();
        }
    }
};
$.ajax(options);


are you using dataType:'jsonp'? if so, and there is an error, there's a bug (?) that it goes to the ether.

if not, for jQuery>=1.5, try adding the statusCode map of handlers to your ajax setup to see if you are getting into each named status:

    ,success: function(a,b,c){
        console.log('success');
        console.log(a);
    }
    ,error: function(a,b,c) {
        console.log('error');
    }
    ,statusCode: {
        200: function(a,b,c) {
            console.log('200');
        }
        ,400: function(a,b,c) {
            console.log('400');
        }
        ,404: function(a,b,c) {
            console.log('404');
        }
        ,500: function(a,b,c) {
            console.log('500');
        }
    }
    ,complete: function(a,b,c) {
        console.log('complete');
        console.log('status: ' + a.status);
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜