I am using laravel 5.0. I want to get base url of laravel page using jquery. I have tried the following function.
function getBaseURL () {
return location.protocol + "//" + location.hostname + (location.port && ":" + location.port) + "/";
}
But this gives only http://localhost
. I need my full base url in jquery. What to do?
You can also use this:
You can call it any where in js files like
"base_url"
It return upto your
public
path without slash at endEx: www.example.com
If you need to add slash at end you can use this..
It return upto your
public
path with slash at endEx: www.example.com/
Do you mean you want the base url of your laravel app available anywhere your javascript?
You can include this in your template.blade.php:
And than access that var anywhere in your javascript:
The solution is easy , All you need to just use below code :-
This variable will return something like http://yourexampledomain.com
Furthermore if you want to add your controllers and action to this url i.e. for Ajax call , then that will be simple too :-
Result is :- http://yourexampledomain.com/controller/action
Now use finalUrl in your calling route for ajax calls.