Get base_url using Jquery in Laravel -


i using laravel 5.0. want base url of laravel page using jquery. have tried following function.

function getbaseurl () {    return location.protocol + "//" + location.hostname + (location.port && ":" + location.port) + "/"; } 

but gives http://localhost. need full base url in jquery. do?

do mean want base url of laravel app available anywhere javascript?

you can include in template.blade.php:

<script type="text/javascript"> var app_url = {!! json_encode(url('/')) !!} </script> 

and access var anywhere in javascript:

console.log(app_url); 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -