Jquery select add values from json
Posted
by
brabertaser1992
on Stack Overflow
See other posts from Stack Overflow
or by brabertaser1992
Published on 2012-10-26T16:37:36Z
Indexed on
2012/10/26
17:01 UTC
Read the original article
Hit count: 159
I have such json:
[
{
"MOD_AXL": 0,
"MOD_CDS_ID": 110000168,
"MOD_CV": 0,
"MOD_CV_CTM": null,
"MOD_ID": 168,
"MOD_MFA_ID": 514,
"MOD_PC": 1,
"MOD_PCON_END": 199007,
"MOD_PCON_START": 196303,
"MOD_PC_CTM": null,
"Name": "2 CV"},
{
"MOD_AXL": 0,
"MOD_CDS_ID": 110004500,
"MOD_CV": 0,
"MOD_CV_CTM": null,
"MOD_ID": 4500,
"MOD_MFA_ID": 514,
"MOD_PC": 1,
"MOD_PCON_END": 198810,
"MOD_PCON_START": 197808,
"MOD_PC_CTM": null,
"Name": "ACADIANE"},
{
"MOD_AXL": 0,
"MOD_CDS_ID": 110001660,
"MOD_CV": 0,
"MOD_CV_CTM": null,
"MOD_ID": 1660,
"MOD_MFA_ID": 514,
"MOD_PC": 1,
"MOD_PCON_END": 197712,
"MOD_PCON_START": 196301,
"MOD_PC_CTM": null,
"Name": "AMI"}
// etc..etc..
]?
But how to set as select value MOD_ID, and as text of select option: Name?
I have this data in text:
$(".man-select").change(function(){
var mfa_id = $(".man-select").val();
console.log(mfa_id);
$.ajax({
url: "/get_models_for_mfa/mfa_id="+mfa_id+".json",
type: "GET",
data: {},
success: function(text) //here is object
{
console.log("getted");
$('.mod-select')
.append($("<option></option>")
.attr("value",text)
.text(text));
},
error: function(){
//alert('?????? javascript');
},
dataType : "html"
});
});
© Stack Overflow or respective owner