22.5 Detecting an AJAX Request
Sometimes its useful to within the route whether a request has been made using AJAX.
Fortunately Laravel provides a method to detect AJAX requests. Let’s take a look.
1 <?php
2
3 // application/routes.php
4 Route::get('content', function() {
5
6 // check to see if the request is
7 // an AJAX one.
8 if (Request::ajax())
9 {
10 // provide the ajax content
11 return View::make('only_content');
12 }
13
14 // provide the full content
15 return View::make('content_with_layout');
16
17 });
The Request::ajax() returns a boolean true if the request is an AJAX request, and boolean
false if not.I would like to say thanks to the following people for buying a copy of Code Happy, thanks!
• William Manley
• Nate Nolting
• Jorijn Schrijvershof
• Caleb Griffin
• Florian Uhlrich
• Stefano Giordano
• Simon Edwards
I’d also like to say thanks to everyone that sent kind emails about the book, thanks for all the
support!
Anil Bist
Skills Laravel
Qualifications :- High School - SLV, College/University - Graphic Era Deemed Univ University,Location :-Dehradun,Dehradun,Uttarakhand,India
Description:-
I started my Professional Journey in 2006 with one of the Web Development Company in Bangalore and my 1st framework was "Ruby on Rail" as Web development and delivered around 5+ Projects using this platform. Then came another dimension as JEE/Sturst framework, Gradually I realized that I want to build something on my own and give my passion and energy on creating something different a
Explore