根据php jQuery中的下拉选项单击按钮时填充文本框

我的过程是这样的:我有一个下拉菜单和文本框。 当我从下拉列表中选择一个id(唯一ID)然后单击“提交”按钮时,要在文本框中显示相应的名称。

我的数据库字段:

  1. id (自动增量)
  2. AgencyName_id (唯一ID)
  3. 名称

dispay.html

  ...Select...  <option value="">    // for input text  // submit button  

dataGet.php

   

myjson.js

       $(document).ready(function(){ $('#agencyID_dwn').change(function(){ var reg_number = $(this).val(); var data_String; data_String = 'reg_number='+reg_number; $.post('dataGet.php',data_String,function(data){ var data= jQuery.parseJSON(data); $('#testid').val(data.Name); }); }); });  

当我点击提交按钮时,我在“dataGet.php”中将数据库结果作为数组。但是在文本框中没有显示结果。我的代码中有任何错误吗?

这是你的答案

你的index.php

       Untitled Document    

  
// for input text // submit button

和你的dataGet.php文件如下

   just ccheck your table name and all will work 

在dataGet.php中尝试这样,

 while ($row = mysqli_fetch_assoc($result)) { echo $row["Name"]; }