简体   繁体   中英

can we fetch values from database and display them in selectbox in javascript

<select name="zone"  id="zone" style="width:100px; height:22px; float:left; margin:0px 0px 0px 0px;">


<?php
    $sql33="select * from tb_zone where nation='Domestic'";
    $query33=mysql_query($sql33);
    while($row33=mysql_fetch_array($query33)) {
?>

<option value="<?php echo  $row33['zone_id']; ?>"><?php echo $row33["zone_name"]; ?></option>

<?php  } ?>

</select>

Hello as above there is a simple script in PHP that is fetching values from database and displaying it. My question is can we do the same task in JavaScript. Means can we fetch values from database and display them in <select> in JavaScript?

The trick is to use AJAX to do it. If you're using jQuery read up on using $.ajax here http://api.jquery.com/jquery.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