json parsing in javascript with jquery

Following is simple example, that uses jquery.ajax function to request json data from any url.

and once data is received,
$.each
is use for looping through all logical record in json data.

jQuery.ajax(
            {
                type: 'POST',
                url: 'http://demourl?tmp=' + Math.random(),
                dataType: 'json',
                data: 'keyword=demo&query=demoquery',
                success: function(jd) {

                    var strResult = '';

                    $.each(jd.posts, function(i, obj) {

                    var strLoop ="";

                    strLoop = strLoop +"<div class='resultrecord'>";
                    strLoop = strLoop + obj.firstname + ' ' + obj.lastname;
                    strLoop = strLoop +"</div>";

                    strResult = strResult + strLoop;
                    });

                    jQuery("#d1").html(strResult);
                }
            }
        );

Leave a comment