Support the ongoing development of Laravel.io →
Requests Views Blade
Last updated 1 year ago.
0

Here's how I do it with jQuery... Will use a very simple example. Let's say you have 2 elements, a #nav button, and a #container

First you prepare a route which is dedicated to loading ajax content..

Route::get('/ajax/GetContent', array(
  'uses'  =>  'AjaxController@loadContent'
));

The controller in question basically loads content from the database (or whatever source you have), and returns html..

Now to the jquery part:

$(document).on('click','#nav', function(){
$.ajax({
    url: rootPath + '/ajax/GetContent',
    type: "GET", // not POST, laravel won't allow it
    success: function(data){
      $data = $(data); // the HTML content your controller has produced
      $('#container').fadeOut().html($data).fadeIn();    
      }
  });
});
  

I hope that was useful.. let me know if you need more..

Last updated 1 year ago.
0

Have a look at Pjax - it takes components of a normal view and updates the url. There's a Laravel Wrapper as well.

0

i think you can use post but in the route file you should use it like this

Route::post('/ajax/GetContent', array(
  'uses'  =>  'AjaxController@loadContent'
));

not

Route::get('/ajax/GetContent', array(
  'uses'  =>  'AjaxController@loadContent'
));
0

ferasallaou said:

i think you can use post but in the route file you should use it like this

Route::post('/ajax/GetContent', array(
 'uses'  =>  'AjaxController@loadContent'
));

not

Route::get('/ajax/GetContent', array(
 'uses'  =>  'AjaxController@loadContent'
));

lol exactly what i was thinking. Thanks btw, the ajax example will help me out to allow submitting POST data without refreshing the page for my users

Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

thobiasn thobiasn Joined 22 Sep 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.