如何在Laravel5中通过ajax和php实现html表单的自动化

如何在Laravel5中通过ajax和php实现html表单的自动化,php,ajax,laravel-5,Php,Ajax,Laravel 5,各位,我是PHP和Ajax新手,我想在我的项目中创建一个函数,当我在表单中选择疾病类型时,我想做什么,如图所示 当我选择病毒性疾病时,我想从数据库中获取病毒性疾病的数据,而无需刷新页面 我的代码是 <legend>Patient Details</legend> <div class="form-group"> <label for="select" class="col-lg-2 control-label">Disease

各位,我是PHP和Ajax新手,我想在我的项目中创建一个函数,当我在表单中选择疾病类型时,我想做什么,如图所示

当我选择病毒性疾病时,我想从数据库中获取病毒性疾病的数据,而无需刷新页面

我的代码是

<legend>Patient Details</legend>
   <div class="form-group">

      <label for="select" class="col-lg-2 control-label">Disease Type</label>
      <div class="col-lg-4">
        <select class="form-control" id="disease_type">
          <option>Select Disease Type</option>
          <option value="ViralD">Viral Diseases</option>
          <option value="InfectionD">Infection Diseases </option>
          <option value="CommonD">Common Diseases</option>
          <option value="NewD">New Diseases </option>
        </select>  

    </div>
      <label for="select" class="col-lg-2 control-label">Disease Name</label>
      <div class="col-lg-4">
        <select class="form-control" id="select">
          <option>Select Disease Name</option>
          <option>2-5</option>
          <option>5-10</option>
          <option>10-20</option>
          <option>20-40</option>
        </select>


    </div>
    </div>
我的路线呢

Route::get('/fetching_names', 'PatientController@get_disease_name');

我会建议你通过一些在线教程或内容来学习ajax。以下链接可能会有所帮助:


我会建议您浏览一些教程或在线内容,这些教程或内容会教您ajax。以下链接可能会有所帮助:


删除了这个无用的答案,因为这个人在使用Laravel。

删除了这个无用的答案,因为这个人在使用Laravel。

创建一个返回JSON的端点,用AJAX调用它,触发表单更新。你能解释一下或给我一个类似示例的教程吗创建一个返回JSON的端点,用AJAX调用它,触发表单更新。你能解释一下或者给我一个类似的例子吗教程很棒,但是要小心你的sql代码容易受到sql注入的攻击。我也在使用Laravel 5来完成这个项目。。这段代码在那里不会很好地工作,但是要小心,您的sql代码容易受到sql注入的攻击。我也在使用Laravel 5来完成这个项目。。此代码在那里不起作用
class PatientController extends Controller
{
    public function get_disease_type()
   {

    $disease_type = DB::table('disease_type')->get();

    return view('admin/add_patient', compact('disease_type'));

   }

   public function get_disease_name(Request $request)
   {

    echo $request->disease_type;
    die();
    $disease_name = DB::table('disease')
    ->where("disease_name",$request->disease_type)
    ->get();

    //return view('add-patient', compact('disease'));
    return response()->json($disease_name);
   }

}
Route::get('/fetching_names', 'PatientController@get_disease_name');