@@ -22,12 +22,14 @@
22 22 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
- onload: callback(responseData) (default = output response to the
23 23 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
console). In the context of the callback, the options object is
24 24 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
"this", noting that this call may have amended the options object
25 25 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
with state other than what the caller provided.
26 26 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
27 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
- - onerror: callback(XHR onload event | exception)
28 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
- (default = event or exception to the console).
27 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ - onerror: callback(XHR onload event | exception) (default = event
28 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ or exception to the console). Triggered if the request generates
29 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ any response other than HTTP 200. In the context of the callback,
30 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ the options object is "this".
29 31 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
30 32 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
- method: 'POST' | 'GET' (default = 'GET'). CASE SENSITIVE!
31 33 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
32 34 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
- payload: anything acceptable by XHR2.send(ARG) (DOMString,
33 35 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
Document, FormData, Blob, File, ArrayBuffer), or a plain object or
@@ -64,17 +66,28 @@
64 66 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
header values. When a map is passed on, all of its keys are
65 67 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
lower-cased. When a given header is requested and that header is
66 68 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
set multiple times, their values are (per the XHR docs)
67 69 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
concatenated together with ", " between them.
68 70 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
69 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
- When an options object does not provide onload() or onerror()
70 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
- handlers of its own, this function falls back to
71 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
- fossil.fetch.onload() and fossil.fetch.onerror() as defaults. The
72 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
- default implementations route the data through the dev console and
73 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
- (for onerror()) through fossil.error(). Individual pages may
74 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
- overwrite those members to provide default implementations suitable
75 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
- for the page's use.
71 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ - beforesend/aftersend: optional callbacks which are called without
72 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ arguments immediately before the request is submitted and
73 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ immediately after it is received, regardless of success or
74 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ error. In the context of the callback, the options object is the
75 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ "this". These can be used to, e.g., keep track of in-flight
76 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ requests and update the UI accordingly, e.g. disabling/enabling DOM
77 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ elements. Any exceptions triggered by beforesend/aftersend are
78 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ caught and silently ignored.
79 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+
80 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ When an options object does not provide
81 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ onload/onerror/beforesend/aftersend handlers of its own, this
82 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ function falls to defaults which are member properties of this
83 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ function with the same name, e.g. fossil.fetch.onload(). The
84 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ default onload/onerror implementations route the data through the
85 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ dev console and (for onerror()) through fossil.error(). The default
86 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ beforesend/aftersend are no-ops. Individual pages may overwrite
87 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ those members to provide default implementations suitable for the
88 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ page's use, e.g. keeping track of how many in-flight
76 89 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
77 90 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
Returns this object, noting that the XHR request is asynchronous,
78 91 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
and still in transit (or has yet to be sent) when that happens.
79 92 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
*/
80 93 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
window.fossil.fetch = function f(uri,opt){
@@ -121,10 +134,12 @@
121 134 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
if('/'===uri[0]) uri = uri.substr(1);
122 135 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
if(!opt) opt = {};
123 136 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
else if('function'===typeof opt) opt={onload:opt};
124 137 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
if(!opt.onload) opt.onload = f.onload;
125 138 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
if(!opt.onerror) opt.onerror = f.onerror;
139 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ if(!opt.beforesend) opt.beforesend = f.beforesend;
140 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ if(!opt.aftersend) opt.aftersend = f.aftersend;
126 141 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
let payload = opt.payload, jsonResponse = false;
127 142 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
if(undefined!==payload){
128 143 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
opt.method = 'POST';
129 144 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
if(!(payload instanceof FormData)
130 145 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
&& !(payload instanceof Document)
@@ -151,10 +166,11 @@
151 166 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
x.responseType = 'text';
152 167 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
}else{
153 168 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
x.responseType = opt.responseType||'text';
154 169 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
}
155 170 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
x.onload = function(e){
171 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ try{opt.aftersend()}catch(e){/*ignore*/}
156 172 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
if(200!==this.status){
157 173 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
opt.onerror(e);
158 174 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
return;
159 175 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
}
160 176 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
const orh = opt.responseHeaders;
@@ -176,9 +192,13 @@
176 192 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
opt.onload.apply(opt, args);
177 193 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
}catch(e){
178 194 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
opt.onerror(e);
179 195 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
}
180 196 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
};
197 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ try{opt.beforesend()}catch(e){/*ignore*/}
181 198 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
if(undefined!==payload) x.send(payload);
182 199 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
else x.send();
183 200 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
return this;
184 201 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
};
202 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+
203 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ window.fossil.fetch.beforesend = function(){};
204 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!
+ window.fossil.fetch.aftersend = function(){};
185 205 { copied = false; pop = false }, 1000)" :class="copied && 'copied'">Copy link Copied!