API Reference:SSXHR (Class)
From Spot Specific Documentation
Class & function index
-
_SSXHR (Class)
Contents |
Class Summary
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
_SSXHR() Provides a proxy for XMLHttpRequests made in the simulator, to overcome cross-domain scripting restrictions.
|
Field Summary
| Field Attributes | Field Name and Description |
|---|---|
|
The inner XMLHttpRequest object, which we'll use to actually perform the request.
|
Methods Summary
| Method Attributes | Method Name and Description |
|---|---|
|
abort()
Aborts the request.
|
|
|
onload()
Fires on completion of the XHR request.
|
|
|
Logs state changes of the _SSXHR object.
|
|
|
open(reqType, url, syncFlag)
Sets the properties of the request by passing them into the 'req' XMLHttpRequest object.
|
|
|
overrideMimeType(newType)
Forces the result of the _SSXHR call's XMLHttpRequest to be returned as a particular MIME type.
|
|
|
send(parameter)
Transmits the request.
|
|
|
setRequestHeader(key, value)
Allows setting HTTP headers of the request using key-value pairs.
|
Class Detail
_SSXHR()
Provides a proxy for XMLHttpRequests made in the simulator, to overcome cross-domain scripting restrictions. Works in exactly the same way as the traditional XMLHttpRequest JavaScript methods, but should be used in preference due to this version also allowing operation in the Simulator. To use the _SSXHR class in a screen, the XHR Feature must be included in that screen.
Example:
Sends the contents of a form to a website via a POST request.
function sin_collector_submit() {
var name = document.getElementById('form_name').value
var email = document.getElementById('form_email').value
if (name=="Name" || email=="E-Mail") {
NativeUI.optionpanel.show("Error", "Please fill out both fields");
return;
}
http = new _SSXHR();
var url = 'http://www.something.com/myscript.php';
var params = 'name='+name+'&email='+email;
http.open('POST', url, true);
http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
http.overrideMimeType('text/xml');
http.onreadystatechange = function() {
if (http.readyState == 4 && http.status == 200) {
var return_data = http.responseXML
if (return_data.getElementsByTagName('value')[0].childNodes[0].nodeValue == -1) {
NativeUI.optionpanel.show('Error', return_data.getElementsByTagName('message')[0].childNodes[0].nodeValue)
} else {
NativeUI.optionpanel.show('Success', return_data.getElementsByTagName('message')[0].childNodes[0].nodeValue)
document.getElementById('form_name').value = "Name";
document.getElementById('form_email').value = "E-Mail";
}
}
}
http.send(params);
}Field Detail
req
The inner XMLHttpRequest object, which we'll use to actually perform the request.
Method Detail
abort()
Aborts the request. Internally, it does this by asking the 'req' XMLHttpRequest object to abort.
onload()
Fires on completion of the XHR request. This should be overridden.
onreadystatechange()
Logs state changes of the _SSXHR object. This should be overridden.
open(reqType, url, syncFlag)
Sets the properties of the request by passing them into the 'req' XMLHttpRequest object. It sets a special proxy URL to intercept requests in the Simulator, thereby getting around cross-domain scripting restrictions for testing purposes.
Parameters:{String} reqTypeThe HTTP method for the request (e.g. GET).{String} urlThe URL to request.{String} syncFlagTBC
overrideMimeType(newType)
Forces the result of the _SSXHR call's XMLHttpRequest to be returned as a particular MIME type.
Parameters:{String} newTypeThe MIME type to force, e.g. 'text/xml'.
send(parameter)
Transmits the request. Internally, it does this by using the 'req' XMLHttpRequest object.
Parameters:parameter
setRequestHeader(key, value)
Allows setting HTTP headers of the request using key-value pairs. Internally, it passes these to the 'req' XMLHttpRequest object.
Parameters:{String} keyThe name of the HTTP header to set.{String} valueThe value to pass into the specified HTTP header.