数据填充通过JS Ajax调用Issue

I am populate data on HTML Page through JavaScript from database using AJAX Call it populates correctly sometime while sometimes not

HTML Portion

<body>
    <div data-role="page" id="properties">
        <div data-role="content" class="hs-content">
            <div class="container_12">
                <div class="basic-info content-wrap">
                    <div class="skip-line"><h3>Select your weapon</h3></div>
                    <ul data-role="listview" data-inset="true" id="weaponList"></ul>
                </div>
            </div>
        </div>
    </div>
</body>

JavaScript

getWeaponsList : function()
{
    var sUrl = "weapons.php";
    WS.request( sUrl,null,'POST', successHandlerUC, failureHandlerUC, false );
    function successHandlerUC( o )
    {
        $('#weaponList').empty();
        var li = '';
        var response = WS.getResponseXML( o );

        // Getting Weapons From DataBase
        var weapons = response.getElementsByTagName('weapon');
        //alert("Total Weapon : "+weapons.length);

        for (var i = 0; i < weapons.length; i++)
        {
            var weapon = weapons.item(i);

            var id = weapon.getElementsByTagName('id');
            id = $(id.item(0)).text();

            var name = weapon.getElementsByTagName('name');
            name = $(name.item(0)).text();

            li += '<li id="'+id+'";><a href="animal-data.html" onClick="HarvestData.saveWeapon('+id+',\''+name+'\')"><span><img title="swords" src="images/bow.png"></span>'+name+'</a></li>';

        }

        $('#weaponList').append(li);
        $('ul#weaponList').listview('refresh');
    }

    function failureHandlerUC( o )
    {

    }
}

Sometimes it show all data on html page but sometime it is not showing any data on page however the in both cases data is come from response (Checked By Using FireBug and Web Developer PlugIn In Firefox)

What is the error or any other problem?? Thanks In Advance

I believe the main problem you were facing was due to additional JavaScript code (not posted in the question) that was causing an error, which was causing the issues discussed in the question. The code you posted should work as is (as far as the HTML getting appended).

I believe this line was the culprit:

$("#gallerypopup a").photoSwipe(options);

This was getting called and no such function photoSwipe() existed. This was most likely causing the strange behavior the OP was seeing.

The bottom line here is, you need to debug your code. If there is an error "unrelated" to the problem you're seeing, fix that error first. Then see if you still have the problem.