An absolute URL is a good idea in ajax, but it is a nicer and easier way. Just declared var siteURL = www.example.com;globally. And used it in every request ajax, as shown below.
<script>
$.ajax({
url: siteURL + '/path/to/file',
type: 'POST',
data: {param1: 'value1'},
});
</script>
As a rule, I declared in the main index file or configuration of the JS file.
source
share