1 回答

TA貢獻1830條經驗 獲得超3個贊
您可能需要更改 data 的變量類型才能循環遍歷它。您可以通過console.log(typeof data)檢查變量的類型。以下是您的問題的可能解決方案,看看這是否對您有幫助。
success:function(data){
console.log(typeof data); // should be string
data = jQuery.parseJSON(data);
console.log(typeof data); // should be object
$.each(data['hasil'], function(key, val){
$.each(val, function(subkey, subval){
console.log(subkey);
console.log(subval);
// all values are assigned to the elements with the same id as their keys(as your code suggests)
$('#' + subkey).val('<value="' + subval + '">');
});
});
}
- 1 回答
- 0 關注
- 145 瀏覽
添加回答
舉報