原生JS 中的 ajax请求

 

get请求

function loadList() {
                    var xhr = new XMLHttpRequest();
                    xhr.open("GET", 'https://api.zhiyedang.cn/api/cms/news/list?cateId=490240980956479488', true);//参数写在url后面
                    xhr.onload = function() {
                        console.log(this)
                        var user = JSON.parse(this.responseText);
                        if (user.code == 200) {
                            console.log(user)
                        }
                    }
                    xhr.send();
                }
                loadList()

 

posted @ 2020-09-15 17:47  路西德  阅读(163)  评论(0)    收藏  举报