title: php - Laravel : how to Load Ajax data after selected changes from dropdown?
body: <p>I want to load some ajax data after selected a value from dropdown in textbox.</p>
  
  <p><strong>Eg:</strong> After selecting a teacher from dropdown, teachers remaining credit  and credit_taken value should be load. How do I do it with ajax?</p>
  
  <p><strong>NB:</strong> Here teacher value has selected from another dropdown selecting in Ajax</p>
  
  <pre><code>&lt;script&gt;
        $('#teacher').on('change',function(e){            
             var teach_id = $('#teacher option:selected').attr('value');
  
               var info=$.get("{{url('ajax-teach')}}",{teach_id:teach_id});
                 info.done(function(data){     
                    $.each(data,function(index,subcatObj){
  
                 /// Here will  be the loaded code   ///
  
                      });                    
          });
  
          info.fail(function(){
            alert('ok');
          });
         });
      &lt;/script&gt;
  </code></pre>
  
  <p>Here is <strong>my controller:</strong></p>
  
  <pre><code>Route::get('ajax-teach',function(Request $request){ 
          $teach_id = $request::input(['teach_id']);          
          $teachers=\App\Teacher::where('teacher_id','=',$teach_id)-&gt;get();
          return Response::json($teachers);   
  });
  </code></pre>
  
  <p>Here is the <strong>view Page:</strong></p>
  
  <pre><code>&lt;div class="form-group"&gt;
      &lt;label for=""&gt;Teacher&lt;/label&gt;
      &lt;select class="form-control input-sm" required name="teacher_id" id="teacher" &gt;
      &lt;option value=""&gt;&lt;/option&gt;
      &lt;/select&gt;
  &lt;/div&gt; 
  
  
  &lt;div class="form-group"&gt;
    &lt;label&gt;Credit to be Taken&lt;/label&gt;         
    &lt;input type="text" name="credit_taken" id="credit_taken" class="form-control" required placeholder="Credit to be Taken"&gt;
  &lt;/div&gt;
  
  &lt;div class="form-group"&gt;
    &lt;label&gt;Remaining Credit&lt;/label&gt;         
    &lt;input type="text" name="remaining_credit" class="form-control" required placeholder="Remaining Credit"&gt;
  &lt;/div&gt;
  </code></pre>