Mercurial > repos > tabletprog
comparison mquery.js @ 9:37d7f60a8ea1
Allow use of tabletproglang programs in script tags
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 21 Mar 2012 21:15:32 -0700 |
parents | 3d1b8e96f5dc |
children | 85fb6ba15bc6 |
comparison
equal
deleted
inserted
replaced
8:04ae32e91598 | 9:37d7f60a8ea1 |
---|---|
30 function show(el, dtype) | 30 function show(el, dtype) |
31 { | 31 { |
32 if (dtype === undefined) { | 32 if (dtype === undefined) { |
33 dtype = 'block'; | 33 dtype = 'block'; |
34 } | 34 } |
35 el.style.display | 35 el.style.display = dtype; |
36 } | 36 } |
37 | 37 |
38 function onReady(fun) | 38 function onReady(fun) |
39 { | 39 { |
40 if (document.readyState == 'complete') { | 40 if (document.readyState == 'complete') { |
66 classes.splice(idx, 1); | 66 classes.splice(idx, 1); |
67 el.className = classes.join(' '); | 67 el.className = classes.join(' '); |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 function ajax(method, url, data, onSuccess, onFail, onOthers) | |
72 { | |
73 var req; | |
74 try { | |
75 req = new XMLHttpRequest(); | |
76 } catch (e) { | |
77 req = new ActiveXObject("Microsoft.XMLHTTP"); | |
78 } | |
79 req.onreadystatechange = function() { | |
80 if (req.readyState == 4) { | |
81 if ((req.status >= 200 && req.status <= 299) || req.status == 0) { | |
82 onSuccess(req); | |
83 } else if(onFail) { | |
84 onFail(req); | |
85 } else { | |
86 console.log('request failed:', req); | |
87 } | |
88 } else if(onOthers) { | |
89 onOthers(req); | |
90 } | |
91 } | |
92 req.open(method, url); | |
93 if (data && 'mime' in data) { | |
94 req.setRequestHeader('Content-Type', data.mime); | |
95 req.send(data); | |
96 } else { | |
97 req.send(data); | |
98 } | |
99 } | |
100 | |
101 function get(url, onSuccess, onFail, onOthers) | |
102 { | |
103 ajax('GET', url, undefined, onSuccess, onFail, onOthers); | |
104 } | |
105 | |
106 function post(url, data, onSuccess, onFail, onOthers) | |
107 { | |
108 ajax('POST', url, data, onSuccess, onFail, onOthers); | |
109 } | |
110 |