Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Response Data in Success callback

Tags:

restkit

Is there any way to access the response data in the success block for a request using the object manager?

[objectManager postObject:[User class] path:@"/users" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
  NSLog(@"success");
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
  NSLog(@"failure");
}];

It seems like there should be some way to use the mapping or operation to get this information as maybe NSData or something.

like image 810
fzf Avatar asked Jan 09 '13 22:01

fzf


People also ask

How can I get specific data from AJAX response?

You can't as it's asynchronous. If you want to do anything with it, you need to do it in a callback. How? Because it's asynchronous, javascript will fire off the ajax request, then immediately move on to execute the next bit of code, and will probably do so before the ajax response has been received.

How do you return a response from an asynchronous call?

Since the promise takes a certain amount of time to either get resolved or rejected, we use the await keyword to wait for the promise to return a response.

How does AJAX return success data?

The ajaxSuccess event is only called if the request is successful. It is essentially a type function that's called when a request proceeds. The function takes three parameters, namely: The data returned from the server, formatted according to the dataType parameter, or the dataFilter callback function.

What is data callback?

A JavaScript function you should provide, which will be invoked when new JSON (“order object”) is obtained from the server. This function must accept 1 parameter, an object. See more information on returned data structure in Accessing the Library from Javascript.


2 Answers

You can get this info from the RKObjectRequestOperation *operation

operation.HTTPRequestOperation.response
operation.HTTPRequestOperation.responseData
operation.HTTPRequestOperation.responseString
like image 190
fzf Avatar answered Sep 18 '22 12:09

fzf


try this

[objectRequestOperation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {

// parse the response---       
 NSDictionary *myDic = [NSJSONSerialization JSONObjectWithData:operation.HTTPRequestOperation.responseData options:NSJSONReadingMutableLeaves error:nil];
  NSLog(@"=======:%@",myDic);
   NSLog(@"MY email============ %@ ",[myDic objectForKey:@"Email"]);      
    } failure:^(RKObjectRequestOperation *operation, NSError *error) {
        RKLogError(@"Operation failed with error: %@", error);
    }];
like image 25
Deepak Sasindran Avatar answered Sep 20 '22 12:09

Deepak Sasindran