http://www.mydomain.com/some/subdir/file.php $.post('/some/subdir/file.php', ...); /** * Retrieves the current root URL. * * @return string the root URL */ $.fn.rootUrl = function() { var url = location.href; return url.substring(0, url.indexOf('/', 7)); };