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)
                        .send();

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

Since:
SproutCore 1.0

Field Summary

Instance Methods

Field Detail

address String
URL of request.
body

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:
null
errorValue SC.Response
Always the current response
Default value:
`this`
headers Hash
Headers from the response. Computed on-demand
Default value:
null
isCancelled Boolean
Set to YES if response is cancelled
Default value:
NO
isError Boolean
Becomes true if there was a failure. Makes this into an error object.
Default value:
NO
isJSON Boolean

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

Default value:
NO
isResponse Boolean
Walk like a duck
isXML Boolean

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

Default value:
NO
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:
null
status Number
The response status code.
Default value:
-100
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:
null
timeoutTimer Number
The timer tracking the timeout
Default value:
null
type String
Type of request. Must be an HTTP method. Based on the request.

Instance Method Detail

cancel()

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

cancelTransport()
Override with concrete implementation to actually cancel the transport.
fire()

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.

invokeTransport()

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

notify()
Notifies any saved target/action. Call whenever you cancel, or end.
Returns:
SC.Response
receiver
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.

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