Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript udefined

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #195790
    mlotfi
    Participant

    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.

    #195792
    Paulie_D
    Member

    Images of code aren’t very helpful

    Could you make a Codepen.io demo?

    #195796
    Shikkediel
    Participant

    From a first glance it is because $(“#”+id) is a jQuery object.
    Instead, it’s value should be logged.

    #195798
    mlotfi
    Participant

    you are correct, but does not know why :

    console.log($(‘#19′).data(“assignedAgencies”))

    always displays undefined.

    #195800
    Shikkediel
    Participant

    Maybe some general explanation of the purpose could help…

    #195804
    mlotfi
    Participant

    I just created a fiddle, but don’t know how to point the url to the defined data :

    http://jsfiddle.net/mlotfi/3sb5qurc/

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.