我无法从品牌和模型概念的API获取数据。onchange品牌应该从API获取模型详细信息并在模型选择中显示

时间:2019-03-20 06:26:59

标签: php codeigniter

我在这个项目中使用了Codeignator,我们从中获得了品牌

<select name="brandId" onchange="getModel(this.value);" required>
  <option value ="2">select</option>
  <?php foreach($masterlist['result']['brand'] as $key => $value) { ?>                                                          
    <option value= "<?php  echo $value['brand_id'] ;?>">
    <?php  echo $value['brand_name'] ;?></option>
  <?php } ?>
</select>

这是功能

 function getModel(value){
    $.ajax({ 
          type: "GET",
           dataType: "json",
           url: "<?php echo site_url().'/welcome/getvehicleModel/'?>"
           data: data,
           success: function(response){  
            console.log(response);              
                }
        });
    }

1 个答案:

答案 0 :(得分:0)

成功:功能(响应){

                console.log(response.result[0]['model_id']);
                if(response.result){
                for(i=0;i<response.result.length;i++){

                var opt = new Option(response.result[i]['model_name'],response.result[i]['model_id']);
                    $("#model").append(opt);

                    }
                }