jQuery $. her ve $. veri

0 Cevap php

i have a script that calls a php file and gets an JSON object from it. I'm tring to get the ids from the object attached to a specific element that is created by iterating with $.each the json object. Here is what i have done so far:

$(document).ready(function()
{
    $("#div2").hide('slow');
    $("#div1").empty().html('<img src="ajax-loader.gif" />');
    $.ajax(
    {
        type: 'post',
        async: true,
        url: "Parents.php",
        data: {'id' : 12200},
        dataType: "json",
        cache: false,
        success: function(json_data)
        {
            $("#div1").empty();
            $.each(json_data, function(key, value)
            {
                $("#div1").append('<p class="node"><b>['+key+']</b> => '+value+'</p>');
                $(this).data('id', key);
            });
        }
    });
    $("p.node").click(function()
    {
        var id = $(this).data('id');
        alert('The ID is: ' + id);
    });
});

Ne elde etmek çalışıyorum bunun farkında her düğüm i tıkladığınızda, bu yüzden hover vb i gibi bu kimliği ile başka bir php dosyası aramak başka bir şey yapmak için bu kimliği kullanabilirsiniz kimliğim yapıyor.

Kundakçı ve fireQuery kullanıyorum ve ben oluşturulan her paragraf bir kimliği vardır ve bunun değeri, tüm için aynı artı son id (145) ait bir değer olduğunu fark ettim.

İşte ben php dosyası (json_encode yöntemi) elde JSON veri:

{"908":"one",
 "143":"two",
 "104":"three",
 "9655":"four",
 "144":"five",
 "142":"six",
 "145":"seven"}

Herhangi bir fikir / yardım peşin olarak Tnx duyacağız.

0 Cevap