From 74f3bd1038b6e9e949bd9713b6325380e124a4ad Mon Sep 17 00:00:00 2001 From: Arturo Garro Date: Tue, 13 May 2014 10:52:00 -0600 Subject: [PATCH] Add a success callback this success callback can help to attach "on" events or triggers when the DOM elements are ready. --- src/js/xhr.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/js/xhr.js b/src/js/xhr.js index 9db85e4..67460d0 100644 --- a/src/js/xhr.js +++ b/src/js/xhr.js @@ -75,7 +75,13 @@ xui.extend({ 'Mobile':'true' } }); - + // Success callback + x$('#left-panel').xhr('/panel', { + success: function() { + alert('On Success callback'); + } + }); + // define a callback with the shorthand syntax x$('#left-panel').xhr('/panel', function() { alert("The response is " + this.responseText); @@ -123,10 +129,12 @@ xui.extend({ req.handleResp = (o.callback != null) ? o.callback : function() { that.html(location, req.responseText); }; req.handleError = (o.error && typeof o.error == 'function') ? o.error : function () {}; + req.handleSuccess = (o.success != null) ? o.success : function() {}; function hdl(){ if(req.readyState==4) { delete(that.xmlHttpRequest); if((/^[20]/).test(req.status)) req.handleResp(); + if((/^[20]/).test(req.status)) req.handleSuccess(); if((/^[45]/).test(req.status)) req.handleError(); } }