I have a Json object as following.
{
"firstName":"John",
"lastName":"Doe"
"123":"456"
}
I want to access they keys and value. After reaching, I will set them into fields. But I don’t why it doesn’t work. I’ve checked its syntax has no problem.
What I’ve tried,
$(document).ready(function f() {
$.ajax('http://soner.dev/test.txt', {
success: function(data, status, xhr) {
$(data).each(function(i,val)
{
$.each(val,function(key,val)
{
console.log(key + " : " + val);
alert(key + " : " + val);
$('#{key}').val(val);
});
});
setTimeout(f, 1000); // refresh the data at each second(data changes at each 1sec)
}
});
});
By the way, $('#{key}').val(val); in which I try to use Template Literals.
$(data)?[], not{}.[1, 2, 3]is an array