开发者

Build a list with JSON and jQuery

I need to build a list using the parameters "name" taken from my file "sendjson.php" (in json, of course). How can i create a list using jQuery like this one?

<div id="firstresultname">Firstresultname</div>
<div id="secondresultname">Secondresultname</div>

I don't know how much result will be so is possible to detect and write th开发者_如何学JAVAe right number on div? Thanks!


$.each(json, function(key, value){
    $("body").append('<div id="'+value+'">'+value+'</div>');
});

or just

$.each(json, function(key, value){
    $("body").append('<div>'+value+'</div>');
});

to retreive json & proccess, do following

$.ajax({
    'url' : 'yoururl.php',
    dataType: 'json',
    success: function(json){
        $.each(json, function(key, value){
            $("body").append('<div>'+value+'</div>');
        });
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜