I am trying to have a form add a comment to the database with ajax. The problem I am having is that ajax cannot find the url because of how my current url is structured
url.com/thread/id
I am trying to have the ajax request sent to
url.com/ajax_comment
If I enter the whole URL it works correctly. However I need to avoid doing so as this script will be installable on multiple domains. So how can I accomplish this without hard coding the url in?
Is there a structure in javascript, similar to PHP where you can do include('./folder/file.php');
or there is another method to accomplish this?
Why not to use relative URLs?
$.ajax({
url: "/ajax_comment",
...
});
A relative url will work. This will retrieve the current domain and append your page string to it:
window.location.protocol+"//"+window.location.hostname+"/ajax_comment"