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

问题描述 投票:-2回答:1
SERVICES.startconference(meet.value, participants, function(res) {

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

.....

}
javascript html json api
1个回答
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也是如此。 祝好运。

© www.soinside.com 2019 - 2024. All rights reserved.