trouble populating data to a select menu dropdown
Hi,
I'm Having trouble populating data from a simple json to a select menu dropdown using jquery.I tried using so many codes,but the problem still persist.Can any 1 please help.
I checked in the console of the browser.There its showing that the data has been fetched and populated.But not showing on the dropdown.I tried two three ways but can't get a way around.
Code :
html
- <select name="MODEL" id="MODELS" data-native-menu="false" data-mini="true">
-
- </select>
js
- $.ajax({
- url : 'ModelDet.json',
- cache: false,
- type : "GET",
- data :{},
- dataType : "json",
- success : function(json) {
- for(i=0;i<json.modelDet.length;i++){
- var temp = json.modelDet[i].MODEL;
- var output = [];
- output.push('<option value="' + temp+'">' + temp + '</option>');
- console.log(output);
- /*var result = $('#MODEL').append($("<option></option>").val(temp).html(temp));*/
- var result = $('#MODELS').append('<option value="' + temp+'">' + temp + '</option>');
- console.log(result);
- }
- }
- });
model
- {
- "modelDet" : [{
- "id" : 1,
- "MODEL_GROUP" : "A",
- "MODEL" : "BMW",
- "MODEL_VARIENT" : "A001",
- "COLOR" : "RED",
- "QTY" : 1
- }, {
- "id" : 2,
- "MODEL_GROUP" : "B",
- "MODEL" : "RENAULT DUSTER",
- "MODEL_VARIENT" : "B001",
- "COLOR" : "RED",
- "QTY" : 1
- }, {
- "id" : 3,
- "MODEL_GROUP" : "C",
- "MODEL" : "AUDI",
- "MODEL_VARIENT" : "C001",
- "COLOR" : "RED",
- "QTY" : 1
- }, {
- "id" : 4,
- "MODEL_GROUP" : "D",
- "MODEL" : "BMW",
- "MODEL_VARIENT" : "D001",
- "COLOR" : "RED",
- "QTY" : 1
- }]
- }