title: Laravel Ajax request not working of a controller
body: <p><img src="https://i.stack.imgur.com/UQQB7.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/mM3nz.png" alt="enter image description here"></p>
  
  <p>I am using laravel 4..2 and have a html onchange function like the image. And showing me the error as the second image.</p>
  
  <p>This AJAX request does not work on create method but it works on index method of a laravel resource controller.</p>
  
  <p>Its happening may be because of laravel controller. Can anybody help me by explaining this. </p>
  
  <pre><code>// Routes.php
  
  Route::resource('index', 'IndexController');
  
      Route::get('ajax-subcat', function(){
          $cat_id = Input::get('cat_id');
          $subcategories = Subcategory::where('parent_ID', '=', $cat_id)-&gt;get();
          return Response::json($subcategories);
      });
  
  // AJAX 
  
    &lt;script&gt;
            $('#category').on('change', function(e){
                console.log(e);
  
                var cat_id = e.target.value;
  
                // AJAX
                $.get('ajax-subcat?cat_id=' + cat_id, function(data){
                         $('#subcategory').empty();
                         $.each(data, function(index, subcatObj){
                        $('#subcategory').append('&lt;option value="'+subcatObj.id+'"&gt;'+subcatObj.name+'&lt;/option&gt;')
  
                             });
  
                        //  console.log(data);
  
  
                        });
                });
  
  &lt;/script&gt;
  </code></pre>