- This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
Viewing 6 posts - 1 through 6 (of 6 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › udefined
Hi,
I wrote this code :
http://s23.postimg.org/mckgtjchn/image.png
http://s18.postimg.org/tb2ysn96x/image.png
the js file is too long, and I am pasting only the place that has problem :
function constructAgenciesData() {
$.ajax({
url: “getAgenciesAndGlobalJson.do”,
dataType: “json”,
success: function(data){
$.each(data, function (id, row) {
var id = row.id;
console.log(“the id inside each : ” +id);
$(“#”+id).data(“assignedAgencies”, row.assignedAgencies).data(“restOfAgencies”, row.restOfAgencies);
console.log(“#id : ” +$(“#”+id));
})
}
});
}
$(function($){
constructAgenciesData();
console.log(“for #19 : “)
console.log($(‘#19’).data(“assignedAgencies”))
……
I don’t know why
console.log($(‘#19’).data(“assignedAgencies”))
is undefined.
Thanks, your help is appreciated.
Images of code aren’t very helpful
Could you make a Codepen.io demo?
From a first glance it is because $(“#”+id)
is a jQuery object.
Instead, it’s value should be logged.
you are correct, but does not know why :
console.log($(‘#19′).data(“assignedAgencies”))
always displays undefined.
Maybe some general explanation of the purpose could help…
I just created a fiddle, but don’t know how to point the url to the defined data :