从数据库JavaScript和Ajax加载数据

时间:2019-07-03 06:31:06

标签: javascript php mysql ajax

我创建了一个表,其中包含值“ $ gender,$ starte_whight,$ end_wight和  $ price”,我试图用ajax和js加载,但是我无法使js脚本与数据库的值一起使用,任何帮助将不胜感激

这里我使用ajax选择性别

 <label for="nombre" class="control-label">gender:</label>

           <div class="form-group">
          <div class="selector-gen">
   <select class="form-control" id="gender" name="clasificacion" required> 
      </select>
           </div>
          </div>
        <script type="text/javascript">
        $(document).ready(function() {
            $.ajax({
                type: "POST",
                url: "../ajax/autocomplete/gen.php",
                success: function(response)
                {
                    $('.selector-gen select').html(response).fadeIn();
                }
            });
        });
         </script>                                                            

这是我加载ajax的方式

  $fetch = "SELECT id,gender FROM table ORDER BY gender"; 
$result = mysqli_query($con, $fetch) or die("no good");
echo '<option value="0">Selec...</option>';
while (($fila = mysqli_fetch_array($result)) != NULL) {
    echo '<option 
  value="'.$fila["gender"].'">'.$fila["gender"].'</option>';
        }

然后输入体重

  <input class="form-control" id="weight" name="whight"/>

然后我将此脚本称为

     function Ticket(gender, weight) {
      this.gender=gender;
    this.weight=weight;
         }

    Ticket.prototype.getPrice=function() {
    var price;
     if(this.gender==="gender" && $starte_whight > end_whight){
      price=$price;
    }

     return price;
   }

    $("#calculate").click(function() {
    var genderOptions=[];
      $("select option:selected").each(function() {
        genderOptions.push($(this).text());
       });

       var newTicket = new 
      Ticket($("#gender").val(),$('#weight').val());
      var multiplyVal = newTicket.weight * newTicket.getPrice();
      $("#yourTicket").val(multiplyVal);

      $("#yourTickets").val(newTicket.getPrice().toFixed(2));
      $("#gen").val(newTicket.gender);
   });

这是使用默认值的脚本示例      https://jsfiddle.net/poojjaval/a9u4mkwy/7

我希望能够创建任何性别值,并能以一定的价格波动

0 个答案:

没有答案