Mercurial > repos > tabletprog
diff 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 |
line wrap: on
line diff
--- a/mquery.js Wed Mar 21 20:33:39 2012 -0700 +++ b/mquery.js Wed Mar 21 21:15:32 2012 -0700 @@ -32,7 +32,7 @@ if (dtype === undefined) { dtype = 'block'; } - el.style.display + el.style.display = dtype; } function onReady(fun) @@ -68,3 +68,43 @@ } } +function ajax(method, url, data, onSuccess, onFail, onOthers) +{ + var req; + try { + req = new XMLHttpRequest(); + } catch (e) { + req = new ActiveXObject("Microsoft.XMLHTTP"); + } + req.onreadystatechange = function() { + if (req.readyState == 4) { + if ((req.status >= 200 && req.status <= 299) || req.status == 0) { + onSuccess(req); + } else if(onFail) { + onFail(req); + } else { + console.log('request failed:', req); + } + } else if(onOthers) { + onOthers(req); + } + } + req.open(method, url); + if (data && 'mime' in data) { + req.setRequestHeader('Content-Type', data.mime); + req.send(data); + } else { + req.send(data); + } +} + +function get(url, onSuccess, onFail, onOthers) +{ + ajax('GET', url, undefined, onSuccess, onFail, onOthers); +} + +function post(url, data, onSuccess, onFail, onOthers) +{ + ajax('POST', url, data, onSuccess, onFail, onOthers); +} +