title: post ajax data with click a link on laravel 5
body: <p>I'm newbie in ajax and laravel 5</p>
  
  <p>I have some problem about passing data when I click a link, I gonna explain you what I want achieve.</p>
  
  <p><strong>here my html code :</strong>
  </p>
  
  <pre><code>//this is the div that i want append with data foreach
  &lt;div id="warung-plain"&gt;
  &lt;/div&gt;
  
  //and those code is links that when i click it will send ajax data
  @foreach($kategoriwarung_all as $kategoriwarung)
      &lt;li style="padding:5px 0px"&gt;
          &lt;a class="kategori-warung" style="text-decoration:none;color:#5ca4a9" href="#"&gt;
             {{ $kategoriwarung-&gt;nama }}
          &lt;/a&gt;
      &lt;/li&gt;
   @endforeach
  
  //this is a html code that i want plain in id="warung-plain" after get the foreach data
  &lt;div class="row" style="margin:3% 0px 0px 0px" id=""&gt;
  @foreach($warung_has_kategoriwarungs[$category_fix] as $Warung)
      &lt;div class="col-md-6" style="margin-bottom:0px;min-height:100px"&gt;
          &lt;ul class="no-padding" style="display:inline-flex;list-style-type: none;width:100%;"&gt;
              &lt;li&gt;
                  &lt;img class="img-circle" src="assets/gambar_contoh/foto.jpg" style="height:60px;width:60px"&gt;
              &lt;/li&gt;
              &lt;li style="padding:0px 0px 0px 15px ;width:100%"&gt;
                  &lt;p class="heading-toko-font" style="font-size:18px;color:#606060"&gt;{{ $Warung-&gt;Warung-&gt;nama  }}&lt;/p&gt;
                  &lt;span class="alamat-toko-font" style="font-size:14px;color:#BCBCBC"&gt;&lt;?php echo $Warung['Warung']['alamat']; ?&gt;&lt;/span&gt;
              &lt;/li&gt;
          &lt;/ul&gt;       
      &lt;/div&gt;
  @endforeach                        
  &lt;/div&gt;   
  </code></pre>
  
  <p>here is my js</p>
  
  <pre><code>&lt;script&gt;
      $(document).ready(function(){
          $(".kategori-warung").click(function(e){ 
              e.preventDefault();
              var category = $(e.target).text();
  
              jQuery.ajax({
                  type: "POST",
                  //after passing data category then system will append 
                  //html code to id="warung-plain"
                  url: "/ambil_kategori/{category}",
                  data: {category: category},
                  success: function(res) {
                      $('#warung-plain').load("/warung_plain/{category}");
                  }
              });   
              $(".warung").fadeIn("slow").show();
              $("#nama-kategori").html(category);
              $(".warung-semua").hide();  
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>this is my controller:</strong>
  </p>
  
  <pre><code>public function index()
  {   
      $Warungs_all = Warung::paginate(10);
      $kategoriwarung_all = kategoriwarung::all();
  
  
      return view('index' , compact('kategoriwarung_all' , 'Warungs_all' ));
  }
  
  
  public function get_warung_by_category($category){
  
      $category_fix = $category;
      $kategoriwarung_all = kategoriwarung::all();
  
      foreach($kategoriwarung_all as $kategoriwarung){
          $kategoriwarung-&gt;nama;
          $kategoriwarung-&gt;id;
          $warung_has_kategoriwarungs[$kategoriwarung-&gt;nama] = warung_has_kategoriwarung::where('kategoriwarung_id' , '=' , $kategoriwarung-&gt;id)-&gt;with(['Warung','kategoriwarung'])-&gt;paginate(10);
      }
  
      return view('daftar_warung' , compact('warung_has_kategoriwarungs' ,'category_fix'));
  }
  
  public function warung_plain($category , IndexController $objek){
      $objek-&gt;get_warung_by_category($category);
  }
  </code></pre>
  
  <p><strong>and last this is my route:</strong>
  </p>
  
  <pre><code>Route::get('/', 'IndexController@index');
  Route::post('/ambil_kategori/{category}',    'IndexController@get_warung_by_category');
  Route::get('/warung_plain/{category}', 'IndexController@warung_plain');
  </code></pre>