JAVASCRIPT
Cross Browser Ajax requests
All samples are using Ink.requireModules
, please read how to use it at Ink.requireModules section
Creates a new XMLHttpRequest object
Method name | Description |
---|---|
new Ajax(url, [options]) | Constructor |
.abort() | Aborts the request if still running. No callbacks are called |
.evalJSON(strJSON, sanitize) | Evaluates a given string as JSON |
.getAllHeaders() | Gets all the HTTP headers from the response |
.getHeader(name) | Gets an HTTP header from the response |
.getResponse() | Gets the ajax response object |
.isJSON(str) | Checks if a given string is valid JSON |
.load(url, callback) | Loads content from a given url through an XMLHttpRequest. |
.ping(url, callback) | Loads content from a given url through an XMLHttpRequest. |
.runStateChange() | Executes the state changing phase of an ajax request |
.setHeaders() | Set the necessary headers for an ajax request. |
.setRequestHeader(name, value) | Sets a new request header for the next http request |
url
Request URLoptions
Request options, containing:options.asynchronous
trueIf false, the request synchronous.options.contentType
Content-type header to be sent. Defaults to 'application/x-www-form-urlencoded'options.cors
Flag to activate CORS. Set this to true if you're doing a cross-origin requestoptions.validateCors
If this is set to `true`, perform a CORS request automatically based on the URL being cross-domain or not.options.delay
Artificial delay. If the request is completed faster than this delay, wait the remaining time before executing the callbacksoptions.evalJS
trueIf 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.options.method
'POST'HTTP request method. POST by default.options.parameters
Request parameters to be sent with the requestoptions.postBody
POST request body. If not specified, it's filled with the contents from parametersoptions.requestHeaders
Key-value pairs for additional request headersoptions.sanitizeJSON
Flag to sanitize the content of responseText before evaluationoptions.timeout
Request timeout in secondsoptions.xhrProxy
URI for proxy service hosted on the same server as the web app, that can fetch documents from other domains. The service must pipe all input and output untouched (some input sanitization is allowed, like clearing cookies). e.g., requesting https://example.org/doc can become /proxy/http%3A%2F%2Fexample.org%2Fdoc The proxy service will be used for cross-domain requests, if set, else a network error is returned as exception.options.onComplete
Callback executed after the request is completed, regardless of what happened during the request.options.onCreate
Callback executed after object initialization but before the request is madeoptions.onException
Callback executed if an exception occurs. Receives the exception as a parameter.options.onFailure
Callback executed if the request fails (requests with status codes different from 2xx)options.onHeaders
Callback executed when headers of the response arrive.options.onInit
Callback executed before any initializationoptions.onSuccess
Callback executed if the request is successful (requests with 2xx status codes)options.onTimeout
Callback executed if the request times outMake an AJAX Request with some options
Code
Submit a form using AJAX POST, serialized with Ink.Dom.FormSerialize
Code
Make an AJAX request to SAPO Photos
using CORS
and print the images
Code
Aborts the request if still running. No callbacks are called
Evaluates a given string as JSON
strJSON
String to be evaluatedsanitize
Flag to sanitize the contentGets all the HTTP headers from the response
Gets an HTTP header from the response
name
Header nameGets the ajax response object
Checks if a given string is valid JSON
str
String to be evaluatedLoads content from a given url through an XMLHttpRequest.
Shortcut function for simple AJAX use cases. Works with JSON, XML and plain text.
url
Request URLcallback
Callback to be executed if the request is successfulCode
Loads content from a given url through an XMLHttpRequest.
Shortcut function for simple AJAX use cases.
url
Request urlcallback
Callback to be executed if the request is successfulExecutes the state changing phase of an ajax request
Set the necessary headers for an ajax request.
Sets a new request header for the next http request
name
Header name.value
New header value.