简体   繁体   中英

How can i send the array result query to ajax request from a selected combo

I have two .php, the first one brings the result for the first combo select, the result is the id that will help to bring the two next values in the form. And the second one bring the array results; list_SalerInfo.php:

   $result = mysqli_query($con,$sql);

        while($row = mysqli_fetch_array($result)) {

             echo '<option value="'.$row[0].'">'.$row[2].'</option>';
             echo '<option value="'.$row[0].'">'.$row[3].'</option>';

        }

This is my file with the form:

<label for="saler">Saler name: <select name="saler" id="saler" >
   <?php include 'idSaler.php'; ?> 
</select> 

<label for="repEmail">Email <select name="repEmail" id="repEmail" >
    </select></label>

<label for="repTelephone">Phone Number<select name="repTelephone" id="repTelephone" >
    </select></label>
</div>   
</form>
<script type="text/javascript">
    $(document).on('change','#saler',function(){
         var val = $(this).val();
         $.ajax({
               url: 'list_SalerInfo.php',
               data: {saler:val},
               type: 'GET',
               dataType: 'html',
               success: function(result){
                    $('#repEmail').html();  
                    $('#repEmail').html(result); 


               }
          });
   });
  </script>

My fist value, goes in "repEmail", but I need to display the second result of the array in the next element in the form "repTelephone".

You should build 2 different arrays in php and then send them as json. You can then build and render the html in your success callback.

Don't forget to change the ajax query dataType to 'json' .

If you need examples how to do it, there are plenty already on the web (search for "php json ajax").

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM