Class: SC.Response

A response represents a single response from a server request and handles the communication to the server. An instance of this class is returned whenever you call SC.Request.send().

SproutCore only defines one concrete subclass of SC.Response,SC.XHRResponse. In order to use SC.Request with a non-XHR request type you should create a custom class that extends SC.Response and set your custom class as the value of responseClass on all requests.

For example,

var request = SC.Request.getUrl(resourceAddress)
                        .set('responseClass', MyApp.CustomProtocolResponse)

To extend SC.Response, please look at the property and methods listed below. For more examples, please look at the code in SC.XHRResponse.

Defined in: response.js

SproutCore 1.0

Field Summary

Instance Methods

Field Detail

address String
URL of request.

The response body or the parsed JSON. Returns a SC.Error instance if there is a JSON parsing error. If isJSON was set, will be parsed automatically.

errorObject SC.Error
The error object generated when this becomes an error
Default value:
errorValue SC.Response
Always the current response
Default value:
headers Hash
Headers from the response. Computed on-demand
Default value:
isCancelled Boolean
Set to YES if response is cancelled
Default value:
isError Boolean
Becomes true if there was a failure. Makes this into an error object.
Default value:
isJSON Boolean

If set then will attempt to automatically parse response as JSON regardless of headers.

Default value:
isResponse Boolean
Walk like a duck
isXML Boolean

If set, then will attempt to automatically parse response as XML regardless of headers.

Default value:
listeners Hash
Returns the hash of listeners set on the request.
originalRequest SC.Request

The request object that originated this request series. Mostly this is useful if you are looking for a reference to the original request. To inspect actual properties you should use request instead.

request SC.Request

Request used to generate this response. This is a copy of the original request object as you may have modified the original request object since then.

To retrieve the original request object use originalRequest.

Default value:
status Number
The response status code.
Default value:
timedOut Boolean

Set to YES if the request timed out. Set to NO if the request has completed before the timeout value. Set to null if the timeout timer is still ticking.

Default value:
timeoutTimer Number
The timer tracking the timeout
Default value:
type String
Type of request. Must be an HTTP method. Based on the request.

Instance Method Detail


Default method just closes the connection. It will also mark the request as cancelled, which will not call any listeners.

Override with concrete implementation to actually cancel the transport.

Called by the request manager when its time to actually run. This will invoke any callbacks on the source request then invoke transport() to begin the actual request.


Called by SC.Response#fire(). Starts the transport by invoking the SC.Response#receive() function.

Notifies any saved target/action. Call whenever you cancel, or end.
receive(callback, context)

Invoked by the transport when it receives a response. The passed-in callback will be invoked to actually process the response. If cancelled we will pass NO. You should clean up instead.

Invokes callbacks on the source request also.

callback Function
the function to receive
context Object
context to execute the callback in
Default method just closes the connection.
YES if this response has not timed out yet, NO otherwise
String representation of the response object
Documentation generated by JsDoc Toolkit 2.4.0 on Wed Apr 08 2015 10:02:21 GMT-0600 (CST)