Skip to content

Instantly share code, notes, and snippets.

View empijei's full-sized avatar
💭
for { Learn() }

Roberto Clapis empijei

💭
for { Learn() }
View GitHub Profile
@empijei
empijei / tinyxhr.js
Last active April 14, 2017 14:14 — forked from shimondoodkin/tinyxhr.js
tiny xhr snippet to do XMLHttpRequest
// license: public domain - original author: Shimon Doodkin - https://gist.github.com/4706967
//
// tinyxhr("http://site.com/ajaxaction",function (err,data,xhr){ if (err) console.log("goterr ",err,'status='+xhr.status); console.log(data) });
// tinyxhr("http://site.com/ajaxaction",function (err,data,xhr){ if (err) console.log("goterr ",err,'status='+xhr.status); console.log(data) },'POST','value1=1&value2=2');
// tinyxhr("http://site.com/ajaxaction.json",function (err,data,xhr){ if (err) console.log("goterr ",err,'status='+xhr.status); console.log(data); console.log(JSON.parse(data)) },'POST',JSON.stringify({value:1}),'application/javascript');
// cb - a callback function like: function (err,data,XMLHttpRequestObject){ if (err) throw err; }
//
function tinyxhr(url, cb, method, post, contenttype, auth, timeout) {
var requestTimeout, xhr;