I am confused as to where I should setup a base URL. Currently I am calling the URL and its extensions as they are:
For example:
$(document).on("pageinit", "#login", function () {
$("#form2").on("submit", function (event) {
$.ajax({
type: "GET",
url: "http://www.websiteurl.com/public/account/login/", //the full url
data: $("#form2").serialize(),
success: function (data) {
if (data.loggedIn) {
alert("logged");
} else {
alert("not logged");
}
}
});
});
});
From my understanding base URL is a string and I just concatenate information to that string such as:
var baseUrl = "http://www.websiteurl.com/";
$(document).on("pageinit", "#login", function () {
$("#form2").on("submit", function (event) {
$.ajax({
type: "GET",
url: baseUrl + "public/account/login/", //using baseUrl
data: $("#form2").serialize(),
success: function (data) {
if (data.loggedIn) {
alert("logged");
} else {
alert("not logged");
}
}
});
});
});
But I believe I am doing it wrong and some sites talk about using PHP to declare baseurl. can I get some advice on how to do that and where should I declare the base URL string.
As a <base>
at the HTML page or as a String
on the js file? Thanks.