In joomla php there I can use $this->baseurl to get the base path, but I wanted to get the base path in jquery.
The base path may be any of the follo
I was just on the same stage and this solution works for me
In the view
addScriptDeclaration('var base = \''.JURI::base().'\'');
$document->addScript('components/com_name/js/filter.js');
?>
In js file you access base as a variable for example in your scenario:
console.log(base) // will print
// http://www.example.com/
// http://localhost/example
// http://www.example.com/sub/example
I do not remember where I take this information to give credit, if I find it I will edit the answer