]> hackdaworld.org Git - outofuni/jsutils.git/commitdiff
added optional error callback
authorhackbard <hackbard@hackdaworld.org>
Sun, 15 Oct 2017 08:24:22 +0000 (10:24 +0200)
committerhackbard <hackbard@hackdaworld.org>
Sun, 15 Oct 2017 08:24:22 +0000 (10:24 +0200)
xhr.js

diff --git a/xhr.js b/xhr.js
index f666ad2adf7d86fca56ee30fb566ae943a46dedb..b97ec03dac0ca276b84f1caa89ce9ad7106bcf96 100644 (file)
--- 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);