我無法從 $.ajax() 請(qǐng)求訪問 JSON 結(jié)果。選擇汽車型號(hào)后,我會(huì)從 api 獲得結(jié)果,但我無法訪問 JSON 響應(yīng)以獲取傳播新下拉列表所需的信息。HTML<div class="row"> <div class="form-group col"> <label>Make</label> <select class="custom-select" id="vMake"> <option selected="" disabled="">Choose Make</option> <?php require "config.php"; $sql = "SELECT * FROM tbl_cars"; $stmt = $pdo->prepare($sql); $stmt->execute(); $cars = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($cars as $cars) { echo "<option id='".$cars['make']."' value='".$cars['make']."'>".$cars['make']."</option>"; } ?> </select> </div> <div class="form-group"> <label>Model</label> <select class="custom-select col" id="vModel"> </select> </div></div>JS$(document).ready(function(){ $('#vMake').on('change', function(){ var make = $(this).val(); var url = "https://vpic.nhtsa.dot.gov/api/vehicles/GetModelsForMake/" + make + "?format=json"; $.ajax({ url: url, type: "GET", dataType: "json", }).done(function(data){ $('#vModel').empty(); $.each(data, function(i, e){ var model = data[i].Model_Name; $('#vModel').append('<option value="' + model +'">'+ model + '</option>'); }); }); });})我正在嘗試獲取結(jié)果的模型名稱。但如下圖所示,我在第二個(gè)下拉列表中未定義。我怎樣才能得到我需要的信息?
AJAX .done() 在 JSON 響應(yīng)中返回未定義的 $.each()
UYOU
2022-10-27 16:37:37