Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Add a success callback #104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/js/xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
}
Expand Down