Class Index | File Index

Classes


Class Alfresco.util.Ajax

Helper class for submitting data to serverthat wraps a
YAHOO.util.Connect.asyncRequest call.

The request methid provides default behaviour for displaying messages on
success and error events and simplifies json handling with encoding and decoding.
Defined in: alfresco.js
Field Summary
Field Attributes Field Name and Description
<static>  
Alfresco.util.Ajax.defaultRequestConfig
The default request config used by method request()
<static>  
Alfresco.util.Ajax.DELETE
Constant for method of type DELETE
<static>  
Alfresco.util.Ajax.FORM
Constant for contentType of type standard XHR form request
<static>  
Alfresco.util.Ajax.GET
Constant for method of type GET
<static>  
Alfresco.util.Ajax.JSON
Constant for contentType of type json
<static>  
Alfresco.util.Ajax.POST
Constant for method of type POST
<static>  
Alfresco.util.Ajax.PUT
Constant for method of type PUT
Method Summary
Method Attributes Method Name and Description
<static>  
Alfresco.util.Ajax.jsonDelete(config)
Helper function for pure json requests, where both the request and
<static>  
Alfresco.util.Ajax.jsonGet(config)
Helper function for pure json requests, where both the request and
<static>  
Alfresco.util.Ajax.jsonPost(config)
Helper function for pure json requests, where both the request and
<static>  
Alfresco.util.Ajax.jsonPut(config)
Helper function for pure json requests, where both the request and
<static>  
Alfresco.util.Ajax.jsonRequest(config)
Helper function for pure json requests, where both the request and
<static>  
Alfresco.util.Ajax.request(config)
Wraps a YAHOO.util.Connect.asyncRequest call and provides some default
<static>  
Alfresco.util.Ajax.sanitizeMarkup(markup)
Parses the markup and returns an array with clean markup (without script elements) and the actual script code
Field Detail
<static> {object} Alfresco.util.Ajax.defaultRequestConfig
The default request config used by method request()

<static> {string} Alfresco.util.Ajax.DELETE
Constant for method of type DELETE

<static> {string} Alfresco.util.Ajax.FORM
Constant for contentType of type standard XHR form request

<static> {string} Alfresco.util.Ajax.GET
Constant for method of type GET

<static> {string} Alfresco.util.Ajax.JSON
Constant for contentType of type json

<static> {string} Alfresco.util.Ajax.POST
Constant for method of type POST

<static> {string} Alfresco.util.Ajax.PUT
Constant for method of type PUT
Method Detail
<static> Alfresco.util.Ajax.jsonDelete(config)
Helper function for pure json requests, where both the request and
response are using json. Will result in a call to request() with
responseContentType set to JSON and method set to DELETE.
Parameters:
{object} config
Description of the request that should be made

<static> Alfresco.util.Ajax.jsonGet(config)
Helper function for pure json requests, where both the request and
response are using json. Will result in a call to request() with
responseContentType set to JSON and method set to GET.
Parameters:
{object} config
Description of the request that should be made

<static> Alfresco.util.Ajax.jsonPost(config)
Helper function for pure json requests, where both the request and
response are using json. Will result in a call to request() with
requestContentType and responseContentType set to JSON and method set to POST.
Parameters:
{object} config
Description of the request that should be made

<static> Alfresco.util.Ajax.jsonPut(config)
Helper function for pure json requests, where both the request and
response are using json. Will result in a call to request() with
requestContentType and responseContentType set to JSON and method set to PUT.
Parameters:
{object} config
Description of the request that should be made

<static> Alfresco.util.Ajax.jsonRequest(config)
Helper function for pure json requests, where both the request and
response are using json. Will result in a call to request() with
requestContentType and responseContentType set to JSON.
Parameters:
{object} config
Description of the request that should be made

<static> Alfresco.util.Ajax.request(config)
Wraps a YAHOO.util.Connect.asyncRequest call and provides some default
behaviour for displaying error or success messages, uri encoding and
json encoding and decoding.

JSON

If requestContentType is JSON, config.dataObj (if available) is encoded
to a json string and set in the request body.

If a json string already has been created by the application it should
be passed in as the config.dataStr which will be put in the rewuest body.

If responseContentType is JSON the server response is decoded to a
json object and set in the "json" attribute in the response object
which is passed to the succes or failure callback.

PARAMETERS

If requestContentType is null, config.dataObj (if available) is encoded
to a normal parameter string which is added to the url if method is
GET or DELETE and to the request body if method is POST or PUT.

FORMS
A form can also be passed it and submitted just as desccribed in the
YUI documentation.

SUCCESS

If the request is successful successCallback.fn is called.
If successCallback.fn isn't provided successMessage is displayed.
If successMessage isn't provided nothing happens.

FAILURE

If the request fails failureCallback.fn is called.
If failureCallback.fn isn't displayed failureMessage is displayed.
If failureMessage isn't provided the "best error message as possible"
from the server response is displayed.

CALLBACKS

The success or failure handlers can expect a response object of the
following form (they will be called in the scope defined by config.scope)

{
config: {object}, // The config object passed in to the request,
serverResponse: {object}, // The response provided by YUI
json: {object} // The serverResponse parsed and ready as an object
}
Parameters:
{object} config
Description of the request that should be made
The config object has the following form:
{
method: {string} // GET, POST, PUT or DELETE, default is GET
url: {string}, // the url to send the request to, mandatory
dataObj: {object}, // Will be encoded to parameters (key1=value1&key2=value2) or a json string if requestContentType is set to JSON
dataStr: {string}, // the request body, will be overriden by the encoding result from dataObj if dataObj is provided
dataForm: {HTMLElement}, // A form object or id that contains the data to be sent with request
requestContentType: {string}, // Set to JSON if json should be used
responseContentType: {string}, // Set to JSON if json should be used
successCallback: {object}, // Callback for successful request, should have the following form: {fn: successHandler, scope: scopeForSuccessHandler}
successMessage: {string}, // Will be displayed using Alfresco.util.PopupManager.displayMessage if successCallback isn't provided
failureCallback: {object}, // Callback for failed request, should have the following form: {fn: failureHandler, scope: scopeForFailureHandler}
failureMessage: {string}, // Will be displayed by Alfresco.util.displayPrompt if no failureCallback isn't provided
execScripts: {boolean}, // Whether embedded