Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel blade use jquery load method

Is there any way to use jquery to render the webpage? Blade keeps reloading the whole page, which is really annoying when you have music running on the website (It will keep stopping). Normally i would use Jquery's .load("HTMLPAGE") method but this doesn't seem to work.

What i did so far: http://pastebin.com/0u1JeHD0

What happens is: first jquery does its thing & after that laravel/blade reloads the whole view.

From what i understand is that you can extend views to replace parts of said views but when i try this it still reloads the whole page.

If you have any questions, please ask as i have a hard time explaining what i exactly mean.

PS: I did not know i needed to say this but: if you are here to get rude, just get off. I'm asking a question and as far as I know this is a site where you can do such things.

like image 839
JordyvD Avatar asked Oct 24 '14 23:10

JordyvD


1 Answers

This was not tested, but should work:

On your routes.php file:

Route::get('/yoururl', function() {
    return View::make('view-to-load');
});

// Laravel 5^
Route::get('/yoururl', function() {
    return view('view-to-load');
});

On your app.js (or whatever your javascript file is named):

$(document).ready(function() {
    $('#containner').load('/yoururl');
  });

This way your blade template with the file name view-to-load.blade.php should be loaded in the HTML elemente with the ID containner.

Hope I had helped :)

Note: This might not be the most correct way of doing this, but its simple enought, that was the point.

like image 149
António Pinto Avatar answered Oct 05 '22 00:10

António Pinto