Class Index | File Index

Classes


Class M.Request


Extends M.Object.
The root class for every request. Makes ajax requests. Is used e.g. for querying REST web services. First M.Request.init needs to be called, then send.
Defined in: request.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
Field Summary
Field Attributes Field Name and Description
 
If set, contains the request's callbacks in sub objects.
 
The data body of the request.
 
Sends the request asynchronously instead of blocking the browser.
 
Processes the request and response as JSON if possible.
 
The HTTP method to use.
 
Holds the jQuery request object
 
This property can be used to specify whether or not to cache the request.
 
This property can be used to specify whether or not to send a timestamp along with the request in order to make every request unique.
 
Optional timeout value of the request in milliseconds.
 
The type of this object.
 
url
The URL this request is sent to.
Method Summary
Method Attributes Method Name and Description
 
Aborts this request.
 
beforeSend(request)
A pre-callback that is called right before the request is sent.
 
init(obj)
Initializes a request.
 
This method is an internal callback that is called right before a request is send.
 
internalOnError(request, msg)
This method is an internal callback that is called if a request failed.
 
internalOnSuccess(data, msg, request)
This method is an internal callback that is called if the request succeeded.
 
onError(request, msg)
The callback to be called if the request failed.
 
onSuccess(data, msg, request)
The callback to be called if the request succeeded.
 
send()
Sends an Ajax request by using jQuery's $.ajax().
Methods borrowed from class M.Object:
bindToCaller, create, destroy, extend, get, include, set
Class Detail
M.Request()
Field Detail
{Object} callbacks
If set, contains the request's callbacks in sub objects. There are three possible callbacks that can be used: - beforeSend - success - error A callback object consists of at least an action but can also specify a target object that determines the scope for that action. If a target is specified, the action can either be a string (the name if a method within the specified scope) or a function. If there is no target specified, the action must be a function. So a success callback could e.g. look like: callbacks: { success: { target: MyApp.MyController, action: 'successCallback' } } Or it could look like: callbacks: { success: { target: MyApp.MyController, action: function() { // do something... } } } Depending on the type of callback, there are different parameters, that are automatically passed to the callback: - beforeSend(request) - success(data, msg, request) - error(request, msg) For further information about that, take a look at the internal callbacks of M.Request: - internalBeforeSend - internalOnSuccess - internalOnError

{String, Object} data
The data body of the request.

{Boolean} isAsync
Sends the request asynchronously instead of blocking the browser. You should almost always make requests asynchronous. You can change this options with the async() helper option (or simply set it directly). Defaults to YES.

{Boolean} isJSON
Processes the request and response as JSON if possible. Defaults to NO.

{String} method
The HTTP method to use. Defaults to GET.

{Object} request
Holds the jQuery request object

sendNoCacheHeader
This property can be used to specify whether or not to cache the request. Setting this to YES will set the 'Cache-Control' property of the request header to 'no-cache'.

sendTimestamp
This property can be used to specify whether or not to send a timestamp along with the request in order to make every request unique. Since some browsers (e.g. Android) automatically cache identical requests, setting this property to YES will add an additional parameter to the request, containing the current timestamp. So if you have any trouble with caching of requests, try setting this to YES. But note, that it might also cause trouble on the server-side if they do not expect this additional parameter.

{Number} timeout
Optional timeout value of the request in milliseconds.

{String} type
The type of this object.

{String} url
The URL this request is sent to.
Method Detail
abort()
Aborts this request. Delegate to jQuery
Returns:
Boolean Indicating whether request exists and is aborted or not

beforeSend(request)
A pre-callback that is called right before the request is sent. Note: This method will be removed with v1.0! Use the callbacks property instead.
Parameters:
{Object} request
The XMLHttpRequest object.

init(obj)
Initializes a request. Sets the parameter of this request object with the passed values.
Parameters:
{Object} obj
The parameter object. Includes: * method: the http method to use, e.g. 'POST' * url: the request url, e.g. 'twitter.com/search.json' (needs a proxy to be set because of Same-Origin-Policy) * isAsync: defines whether request should be made async or not. defaults to YES. Should be YES. * isJSON: defines whether to process request and response as JSON * timout: defines timeout in milliseconds * data: the data to be transmitted * beforeSend: callback that is called before request is sent * onError: callback that is called when an error occured * onSuccess: callback that is called when request was successful

internalBeforeSend(request)
This method is an internal callback that is called right before a request is send.
Parameters:
{Object} request
The XMLHttpRequest object.

internalOnError(request, msg)
This method is an internal callback that is called if a request failed.
Parameters:
{Object} request
The XMLHttpRequest object.
{String} msg
The error message.

internalOnSuccess(data, msg, request)
This method is an internal callback that is called if the request succeeded.
Parameters:
{String|Object} data
The data returned from the server.
{String} msg
A String describing the status.
{Object} request
The XMLHttpRequest object.

onError(request, msg)
The callback to be called if the request failed. Note: This method will be removed with v1.0! Use the callbacks property instead.
Parameters:
{Object} request
The XMLHttpRequest object.
{String} msg
The error message.

onSuccess(data, msg, request)
The callback to be called if the request succeeded. Note: This method will be removed with v1.0! Use the callbacks property instead.
Parameters:
{String|Object} data
The data returned from the server.
{String} msg
A String describing the status.
{Object} request
The XMLHttpRequest object.

send()
Sends an Ajax request by using jQuery's $.ajax(). Needs init first!

Documentation generated by JsDoc Toolkit 2.4.0 on Wed Jan 25 2012 20:41:10 GMT+0100 (MEZ)