function setBaseForAjax(base){ var oa = $.ajax; //keep a reference to the actual ajax call $.ajax = function(){ var len = arguments.length, newArgs = [], newUrl = len === 2 && (typeof arguments[0]).toLowerCase() === 'string' ? arguments[0]: null, newObj = len === 2 && (typeof arguments[1]).toLowerCase() === 'object' ? arguments[1] : (len === 1 && (typeof arguments[0]).toLowerCase() === 'object' ? arguments[0] : null); if(newUrl){ newUrl = base + newUrl; newArgs.push(newUrl); } if(newObj){ newObj.url = base + newObj.url; newArgs.push(newObj); } oa.apply(window, newArgs); //call the real $.ajax method with the modified params }; } setBaseForAjax('/home'); //set the base for every ajax call in the application.