view raw
Praveen Srinivasan Praveen Srinivasan - 9 months ago 157
jQuery Question

Get base_url using Jquery in Laravel

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
. I need my full base url in jquery. What to do?


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:

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

And than access that var anywhere in your javascript: