<fetch>
The <fetch>
element can be used wherever executable content is allowed and has a structure similar to <send>
. It provides SCXML running on Web clients with easy access to the familiar HttpRequest facility used in most Web applications, and, unlike <send>
, it makes the HTTP response available to the calling SCXML instance by sending callback events.
The namespace for <fetch>
as well as its <header>
children must be "http://www.jsscxml.org", for which I suggest the shorthand "jssc". Thus:
<scxml xmlns="http://www.w3.org/2005/07/scxml" xmlns:jssc="http://www.jsscxml.org"> … <jssc:fetch target=… <jssc:header …/> <content expr="…"/> </jssc:fetch> …
Name | Required | Type | Default value | Valid values | Description |
---|---|---|---|---|---|
callback | false, and no more than one of those two | EventType.datatype | none | Name of the event that will be sent when the HTTP response is available. | |
callbackexpr | Vale expression | none | Evaluates when the <fetch> element is executed, used as if there had been a callback attribute with the resulting value. | ||
target | true, and only one of those two | URI | none | Any value accepted by XmlHttpRequest() | The request wil be sent there. |
targetexpr | Vale expression | none | Evaluates when the <fetch> element is executed, used as if there had been a target attribute with the resulting value. | ||
enctype | false | Fetch.datatype | text | one of ["text", "url", "json", "xml"] | The request data will be serialized, and its MIME type selected, according to this value. |
The <fetch>
element also implements the namelist
attribute in exactly the same way as <send>
.
<param>
elements, treated as usual. Those elements only contribute to the request's body.<header>
elements, with the same syntax as <param>
, but only contribute to the request's headers. Unlike <param>
, multiple <header>
s with the same name (or the same name as a predefined header) will result in only the last value (in document order) being used for that header.<content>
element; if present, there should be no sibling <param>
elements and namelist values will be ignored, as this element's contents will be used as the entire data for the request.When executed, the <fetch>
element causes an XMLHttpRequest to be sent to the specified target.
error.communication.callback
(where callback is the value supplied by the callback
or callbackexpr
attributes) is placed into the internal queue.callback.failed
event is placed in the external queue, with the XMLHttpRequest object in its data field. Note that the user may see the exact reason in the JavaScript console, but client-side script does not have access to it and thus cannot tell it to the calling SCXML.callback.done
event is placed in the external queue, with the XMLHttpRequest object in its data field. You can use conditions such as cond="_event.data.status==200"
to further separate the outcomes.