如何在javascript中映射json对UI的响应

时间:2017-12-23 17:23:23

标签: javascript html json api

SERVICES.startconference(meet.value, participants, function(res) {

Log.d("div", "getting success response and posting to new tab", res&& res.OUTERHTML);

.....

}

1 个答案:

答案 0 :(得分:0)

以下是您可以使用的一些代码:

    <script>
    let use_api = function(){
        req = new XMLHttpRequest()
        req.setRequestHeader("Content-type", "application/json");
        req.onreadystatechange = function(){
            if(req.readyState == 4 && req.status==200){
               let data = JSON.parse(xhr.responseText);
               //here you should update your UI with the received data!  
            }
        }
        let req_body = JSON.stringfy({"username":"asdfasdf"}) //username is just an example, you should write things you want to send to API endpoint
        req.open('POST',url,true)
        req.send(req_body)

    }
</script>

也可以查看this。 祝你好运。