且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何正确处理则httpStatus code

更新时间:2023-01-01 10:31:48

解决方法如下:

jQuery.ajax({
        网址:网址,
        数据类型:JSON,
        状态code:{
          404:功能(){警报(404); },
          200:函数(){警报(200); },
          201:函数(){警报(201); },
          202:功能(){警报(202); }
        } / *,
        成功:功能(数据){
          开关(data.status){
            案做:
              / *把它显示给用户* /
              打破;
          }
        } * /
        });

不知怎么的,成功的,方法是在冲突的则httpStatus code-地图

问候斯特凡

I would like to react on http status-codes (like 200, 201 or 202) with the new feature (http://api.jquery.com/jQuery.ajax). But the function is ignoring my 201 and 202 callbacks.

This error occures with firefox-4.0_b10 and chromium-9.0

I'm looking forward to fix this little issue.

Regards Stefan

My code-snipped:

jQuery.ajax({
        url: url,
        dataType: 'json',
        statusCode: {
          404:function() { alert("404"); },
          200:function() { alert("200"); },
          201:function() { alert("201"); },
          202:function() { alert("202"); }
        },
        success: function(data){
          switch(data.status) {
            case 'done':
              /* display it to the User */
              break;
          }
        });

The solution is the following:

jQuery.ajax({
        url: url,
        dataType: 'json',
        statusCode: {
          404:function() { alert("404"); },
          200:function() { alert("200"); },
          201:function() { alert("201"); },
          202:function() { alert("202"); }
        }/*,
        success: function(data){
          switch(data.status) {
            case 'done':
              /* display it to the User */
              break;
          }
        }*/
        });

Somehow, the success-method is in conflict with the httpStatusCode-Map

Regards Stefan