[Elements] are optional
Defined in
Communication/Ajax/0.1/lib.js
Class SAPO.Communication.Ajax
class
SAPO.Communication.Ajax
Inclusion link: http://js.sapo.pt/SAPO/Communication/Ajax/0.1/
Sample: http://js.sapo.pt/SAPO/Communication/Ajax/sample/
Constructor Summary
Function Summary
Constructor Details
constructor Ajax
Ajax(String
url, [Object
options])
Creates a new cross browser XMLHttpRequest object
Parameters:
url
- request url
[options]
- request options -
Boolean asynchronous- if the request should be asynchronous. true by default. -
String method- HTTP request method. POST by default. -
Object parameters- Request parameters which should be sent with the request -
Number timeout- Request timeout -
String postBody- POST request body. If not specified, it's filled with the contents from parameters -
String encoding- Content encoding. Defaults to 'UTF-8' -
String contentType- Content-type header to be sent. Defaults to 'application/x-www-form-urlencoded' -
Object requestHeaders- key-value pairs for additional request headers -
Function onComplete- Callback executed after the request is completed, no matter what happens during the request. -
Function onSuccess- Callback executed if the request is successful (requests with 2xx status codes) -
Function onFailure- Callback executed if the request fails (requests with status codes different from 2xx) -
Function onException- Callback executed if an exception occurs. Receives the exception as a parameter. -
Function onCreate- Callback executed after object initialization but before the request is made -
Function onInit- Callback executed before any initialization -
Function onTimeout- Callback executed if the request times out -
Boolean|String evalJS- If the request Content-type header is application/json, evaluates the response and populates responseJSON. Use 'force' if you want to force the response evaluation, no matter what Content-type it's using. Defaults to true. -
Boolean sanitizeJSON- Sanitize the content of responseText before evaluation
Function Details
function evalJSON
Object
evalJSON(String
str, Boolean
sanitize)
Evaluates a given string as json
Parameters:
str
- String to be evaluated
sanitize
- whether to sanitize the content or not
Returns:
Json content as an object
function isJSON
Boolean
isJSON(String
str)
Checks if a given string is valid json
Parameters:
str
- String to be evaluated
Returns:
True if the string is valid json
function load
Object
load(String
url, Function
callback)
Loads content from a given url through a XMLHttpRequest. Shortcut function for simple AJAX use cases.
Parameters:
url
- request url
callback
- callback to be executed if the request is successful
Returns:
XMLHttpRequest object