define(['dojo/_base/xhr','dojo/_base/json','dojo/_base/connect'], function(xhr,json,connect){ return new (function(){ var self = this; this.post = function(path,args) { var dfd = xhr.post({ url: "../server/api.php/"+path, handleAs: "json", headers: { "Content-Type": "application/json" }, rawBody: json.toJson(args) }); dfd.then( function(){}, self.defaultErrorHandler); return dfd; }; this.defaultErrorHandler = function(error) { var msg = "An error occured!"; try { msg = json.fromJson(error.responseText).errorMsg; } catch (ex) { msg = error.message; } self.notify(msg,'error'); }; this.notify = function(text,type) { connect.publish('/rft/notify',{ text: text, type: type }); }; })(); });