<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 |
|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 |
|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.|
<fetch> element also implements the
namelist attribute in exactly the same way as
<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
<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
callbackexprattributes) is placed into the internal queue.
callback.doneevent 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.