doukong6031 2016-03-18 03:00
浏览 157
已采纳

使用JavaScript将数据json显示到网页中

I found the problem will display the results jSon to a web page at run time data is empty or blank web page, if anyone could help me ?

This my variable declare

var xmlhttp = new XMLHttpRequest();
var url = "http://adisapu10022.besaba.com/smsVerify/json.php";

xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        myFunction(xmlhttp.responseText);
    }
}
xmlhttp.open("GET", url, true);
xmlhttp.send();

This my function

  function myFunction(response) {
        var arr = JSON.parse(response);
        var i;
        var out = "<table>";

        for(i = 0; i < arr.length; i++) {
            out += "<tr><td>" +
            arr[i].Foto +
            "</td><td>" +
            arr[i].Komoditas +
            "</td><td>" +
            arr[i].Harga +
            "</td><td>" +
            arr[i].Pengunggah +
            "</td><td>" +
            arr[i].Telp +
            "</td><td>" +
            arr[i].Unggah +
            "</td></tr>";
        }
        out += "</table>";
        document.getElementById("id01").innerHTML = out;
    }

</div>
  • 写回答

1条回答 默认 最新

  • doupo1865 2016-03-18 03:33
    关注

    I thing your json string is invalid. Check at

    "Komoditas":"Sepatu Nike",{"Harga":"900 Ribu /kg"
    

    The right format is

    "Komoditas":"Sepatu Nike","Harga":"900 Ribu /kg"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog