duandi2853 2013-08-12 13:47
浏览 20
已采纳

数据填充通过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

  • 写回答

1条回答 默认 最新

  • dongmeiwei0226 2013-08-20 14:15
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效