0
<script type="text/javascript">
    function get_test_json(){
        var HTML = "";
        var ClientHTML = "";
        var nomor = 1;
        HTML = '<table data-role="table" id="table-custom-2" data-mode="columntoggle" class="ui-body-d ui-shadow table-stripe ui-responsive" data-column-btn-theme="a" data-column-btn-text="Pilih Kolom" data-column-popup-theme="a">';
        HTML += "<thead>";
        HTML += '<tr class="ui-bar-a">';
        HTML += '<th data-priority="2">No</th>';
        HTML += '<th data-priority="3">Foto</th>';
        HTML += '<th>Nama</th>';
        HTML += '<th data-priority="5">Keterangan</th>';
        HTML += '</tr>';
        HTML += '</thead>';
        HTML += '<tbody>';
        $.getJSON("http://localhost/JSON_test/my_json_list.php", function(person){
            $.each(person, function(key, value){
                $.each(value, function(names, specs){
                    ClientHTML += '<tr>'; 
                    ClientHTML += '<th>'+nomor+'</th>'; 
                    ClientHTML += '<td><img src="" alt="" height="" width=""></td>'; 
                    ClientHTML += '<td>'+names+'</td>'; 
                    ClientHTML += '<td><a href="http://localhost/4r.mobile.kemensos/profil_peneliti.html">'+specs+'</a></td>'; 
                    ClientHTML += '</tr>';
                    nomor = nomor+1;
                });
            });
        });
        alert(ClientHTML); // this is the problem
        HTML += ClientHTML;
        HTML += '</tbody>';
        HTML += '</table>';
        document.getElementById("test").innerHTML = HTML;
    }
    </script>

当我删除警报时,ClientHTML 变量为空。
我很抱歉我的英语不好和一些转储代码,我是新手,
谢谢你的帮助

4

2 回答 2

1

这不是警报和非警报的问题——它是时间问题

 $.getJSON("http://localhost/JSON_test/my_json_list.php", function(person){
            $.each(person, function(key, value){
                $.each(value, function(names, specs){
                    ClientHTML += '<tr>'; 
                    ClientHTML += '<th>'+nomor+'</th>'; 
                    ClientHTML += '<td><img src="" alt="" height="" width=""></td>'; 
                    ClientHTML += '<td>'+names+'</td>'; 
                    ClientHTML += '<td><a href="http://localhost/4r.mobile.kemensos/profil_peneliti.html">'+specs+'</a></td>'; 
                    ClientHTML += '</tr>';
                    nomor = nomor+1;
                     HTML += ClientHTML;
                   HTML += '</tbody>';
                   HTML += '</table>';
                  document.getElementById("test").innerHTML = HTML;
                });
        });
    });

完成 ajax 请求后,您必须执行操作。

于 2013-07-17T04:30:38.607 回答
0

我相信这会奏效。只需将它们分成两个功能。

<script>
function get_test_json(){
  var nomor = 1;
  var ClientHTML = "";
  $.getJSON("http://localhost/JSON_test/my_json_list.php", function(person){

        $.each(person, function(key, value){
            $.each(value, function(names, specs){
                ClientHTML += '<tr>'; 
                ClientHTML += '<th>'+nomor+'</th>'; 
                ClientHTML += '<td><img src="" alt="" height="" width=""></td>'; 
                ClientHTML += '<td>'+names+'</td>'; 
                ClientHTML += '<td><a href="http://localhost/4r.mobile.kemensos/profil_peneliti.html">'+specs+'</a></td>'; 
                ClientHTML += '</tr>';
                nomor++;
            });
        });


        get_next(ClientHTML);
    });


}

function get_next(ClientHTML){
    var HTML = "";
    HTML += '<table data-role="table" id="table-custom-2" data-mode="columntoggle" class="ui-body-d ui-shadow table-stripe ui-responsive" data-column-btn-theme="a" data-column-btn-text="Pilih Kolom" data-column-popup-theme="a">';
    HTML += "<thead>";
    HTML += '<tr class="ui-bar-a">';
    HTML += '<th data-priority="2">No</th>';
    HTML += '<th data-priority="3">Foto</th>';
    HTML += '<th>Nama</th>';
    HTML += '<th data-priority="5">Keterangan</th>';
    HTML += '</tr>';
    HTML += '</thead>';
    HTML += '<tbody>';

    HTML += ClientHTML;
    HTML += '</tbody>';
    HTML += '</table>';
    document.getElementById("test").innerHTML = HTML;

    $('#table-custom-2').table('refresh');
}
</script>
于 2013-07-17T04:48:30.553 回答