Skip to main content
 首页 » 编程设计

jquery之如何正确处理httpStatuscode

2026年07月28日9rubylouvre

我想使用新功能 (http://api.jquery.com/jQuery.ajax) 对 http 状态代码(如 200、201 或 202)使用react。但该函数忽略了我的 201 和 202 回调。

firefox-4.0_b10 和 chromium-9.0 会出现此错误

我期待解决这个小问题。

问候斯特凡

我的代码片段:

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

请您参考如下方法:

解决办法如下:

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

不知何故,成功方法与httpStatusCode-Map冲突

问候斯特凡