求教於各位大大!
目前小弟能後端產生Json給Ajax取得
Json內容整理後如下:
[
{
"Name":"Billing",
"AddressTypeID":1
},
{
"Name":"Home",
"AddressTypeID":2
},
{
"Name":"Main Office",
"AddressTypeID":3
},
{
"Name":"Primary",
"AddressTypeID":4
}
]
想實作出按個Button執行Ajax解析Json後,將Name跟AddressTypeID
塞到Dropdownlist(<select>)作Text跟Value,
但執行結果會變成四個選項值都是undefind!
Ajax如下:
$.ajax({
type: "POST",
url: "/AddressTypes/get",
data: '{}',
datatype: "json",
contentType: "application/json; charset=utf-8",
success: function (result) {
//document.writeln(result);
obj = $.parseJSON(result);
var ddl = $("#ss");
ddl.empty().append('<option selected="selected" value="0">
Please select</option>');
$.each(obj, function () {
ddl.append("<option value='" + obj.AddressTypeID + "'>"
+ obj.Name + "</option>");
});
},
error: function () {
alert("Error !!")
}
});
懇請賜教!(_ _)