-
Notifications
You must be signed in to change notification settings - Fork 10
/
fetch.html
70 lines (55 loc) · 4.58 KB
/
fetch.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<html>
<head>
<meta charset="utf-8">
<title>JSSCxml <fetch> documentation</title>
<style>
h1{ font-weight: normal; }
article h1{
background-color: #d7fbc1;
}
article{
margin-bottom: 2em;
}
</style>
</head>
<body>
<h1>JSSCxml <code><fetch></code></h1>
<p>The <code><fetch></code> element can be used wherever executable content is allowed and has a structure similar to <code><send></code>. It provides SCXML running on Web clients with easy access to the familiar HttpRequest facility used in most Web applications, and, unlike <code><send></code>, it makes the HTTP response available to the calling SCXML instance by sending callback events.</p>
<section><h1>Namespace</h1>
<p>The namespace for <code><fetch></code> as well as its <code><header></code> children must be "http://www.jsscxml.org", for which I suggest the shorthand "jssc". Thus:
<pre><scxml xmlns="http://www.w3.org/2005/07/scxml" xmlns:jssc="http://www.jsscxml.org">
…
<jssc:fetch target=…
<jssc:header …/>
<content expr="…"/>
</jssc:fetch>
…</pre>
</section>
<section><h1>Attribute detail</h1>
<table><thead><tr>
<th>Name</th><th>Required</th><th>Type</th><th>Default value</th><th>Valid values</th><th>Description</th></tr>
</thead><tbody>
<tr><td>callback</td><td rowspan="2">false, and no more than one of those two</td><td>EventType.datatype</td><td>none</td><td></td><td>Name of the event that will be sent when the HTTP response is available.</td></tr>
<tr><td>callbackexpr</td><td>Vale expression</td><td>none</td><td></td><td>Evaluates when the <code><fetch></code> element is executed, used as if there had been a <code>callback</code> attribute with the resulting value.</td></tr>
<tr><td>target</td><td rowspan="2">true, and only one of those two</td><td>URI</td><td>none</td><td>Any value accepted by XmlHttpRequest()</td><td>The request wil be sent there.</td></tr>
<tr><td>targetexpr</td><td>Vale expression</td><td>none</td><td></td><td>Evaluates when the <code><fetch></code> element is executed, used as if there had been a <code>target</code> attribute with the resulting value.</td></tr>
<tr><td>enctype</td><td>false</td><td>Fetch.datatype</td><td>text</td><td>one of ["text", "url", "json", "xml"]</td><td>The request data will be serialized, and its MIME type selected, according to this value.</td></tr>
</tbody></table>
<p>The <code><fetch></code> element also implements the <code>namelist</code> attribute in exactly the same way as <code><send></code>.</p>
</section>
<section><h1>Children</h1>
<ul>
<li>0 or more <code><param></code> elements, treated as usual. Those elements only contribute to the request's body.</li>
<li>0 or more <code><header></code> elements, with the same syntax as <code><param></code>, but only contribute to the request's headers. Unlike <code><param></code>, multiple <code><header></code>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.</li>
<li>0 or one <code><content></code> element; if present, there should be no sibling <code><param></code> elements and namelist values will be ignored, as this element's contents will be used as the entire data for the request.</li>
</ul>
</section>
<section><h1>Behavior</h1>
<p>When executed, the <code><fetch></code> element causes an <a href="http://www.w3.org/TR/XMLHttpRequest/">XMLHttpRequest</a> to be sent to the specified target.</p>
<ul><li>If the target is invalid and detected as such immediately, an <code>error.communication.<var>callback</var></code> (where <var>callback</var> is the value supplied by the <code>callback</code> or <code>callbackexpr</code> attributes) is placed into the internal queue.</li>
<li>If the target is unreachable or denied by security restrictions (in fact, any error raised asynchronously by the XMLHttpRequest object), a <code><var>callback</var>.failed</code> 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.</li>
<li>Otherwise, once the response has been retrieved, and even if it bears an error code (such as 404 or 500), a <code><var>callback</var>.done</code> event is placed in the external queue, with the XMLHttpRequest object in its data field. You can use conditions such as <code>cond="_event.data.status==200"</code> to further separate the outcomes.</li>
</ul>
</section>
</body>
</html>