开发者

Using jQuery data for processing RESTfull requests

开发者 https://www.devze.com 2023-01-26 10:35 出处:网络
I am trying to filter somehow the request response based on the returned status code. I found how I can get the status code using the "complete" statement, but I do not know how to get the h

I am trying to filter somehow the request response based on the returned status code. I found how I can get the status code using the "complete" statement, but I do not know how to get the handler to the data. In the example I want to include the error statement and the success statement in the complete handler, and being able there to process the data.

$.ajax({
      dataType: 'json',
      url:  url,
      cache: false,
      type: 'GET',
      async: true,
      error: function(){
            //process error
        
       },
      success: function(data){
        //process data
      },
      complete: function(transport) {

        switch(transport.status){
        开发者_高级运维    case 200:
                //process data
                break;
            case 202:
                //process data
            
                break;
            case 304:
                //do not process data
            
                break;
            default:
                //default processing
                break;
        }
      }
                  
       }
    });


You actual response is transport

So you can use transport.responseText to get the string response (before it's parsed, that happens in success)

0

精彩评论

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