Praveen Srinivasan Praveen Srinivasan - 1 year ago 257
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?

Answer Source

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:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download