title: Ajax get shopping cart on page load
body: <p>I want to load the shopping cart whenever the page is loaded but nothing happens. The console log is not telling me anything either. I have a post to cart system that works fine, so I cant figure out why this doesnt work.
  I am using Laravel with a shopping cart plugin. </p>
  
  <pre class="lang-js prettyprint-override"><code>$(document).ready(function() {
    $.ajaxSetup({
      headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
      }
    });
  
    $.ajax({
      type: 'get',
      url: '{{route("getCart")}}',
      error: function(data) {
        var errors = data.responseJSON;
        console.log(errors);
      },
      dataType: 'json',
      success: function(data) {
        $('#cartResult').html(data.cartCount)
      },
    });
  });
  </code></pre>
  
  <pre class="lang-php prettyprint-override"><code>public function cartGet() 
  {
    $cartCount = Cart::content() - &gt; count();
    $data = array('cartCount' =&gt; $cartCount);
    echo json_encode($data);
  }
  </code></pre>