how to handle httpStatuscode correctly

我的梦境 提交于 2019-12-07 05:59:32

问题


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

回答1:


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



来源:https://stackoverflow.com/questions/4935615/how-to-handle-httpstatuscode-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!