From 2a06596c2667e61c8750e43c1b7c33361bd82c27 Mon Sep 17 00:00:00 2001 From: hackbard Date: Sun, 15 Oct 2017 10:24:22 +0200 Subject: [PATCH] added optional error callback --- xhr.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/xhr.js b/xhr.js index f666ad2..b97ec03 100644 --- a/xhr.js +++ b/xhr.js @@ -5,7 +5,7 @@ * */ -function xhr(type,url,data,cb) { +function xhr(type,url,data,cb,cberr) { var ao={ url: url, type: type, @@ -13,6 +13,11 @@ function xhr(type,url,data,cb) { cb(ret); } }; + if(cberr!==undefined) { + ao.error=function(xhr,stat,err) { + cberr(xhr,stat,err); + }; + }; if((data!==undefined)&&(data!==null)) { if(typeof data != "string") ao.data=JSON.stringify(data); -- 2.20.1