-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathxhr.js
More file actions
33 lines (30 loc) · 739 Bytes
/
xhr.js
File metadata and controls
33 lines (30 loc) · 739 Bytes
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
/*
This deals with the details of HTTP requests
used to fetch SCXML docs and to send remote events.
*/
function XHR(target, caller, callback, postData, onerror)
{
this.target=target
this.callback=callback
this.caller=caller
this.onerror=onerror
with(this.req=new XMLHttpRequest())
{
open(postData?"POST":"GET",target,true)
onreadystatechange=XHR.handler(this)
overrideMimeType("application/scxml+xml")
send(postData || null)
}
}
XHR.handler=function (xhr)
{
function f()
{
if(xhr.req.readyState<4) return
if(xhr.req.status == 200) xhr.callback.call(xhr.caller,xhr)
else if(xhr.onerror) xhr.onerror.call(xhr.caller,xhr)
else throw "HTTP error " + xhr.req.status
+ " : " + xhr.req.statusText
}
return f
}