未捕获的Typeerror不是函数

时间:2020-04-13 11:01:08

标签: arrays ajax class

我试图在另一个方法中包含一个方法,并且它们在同一类上,但是我收到此错误 我需要这方面的帮助 未捕获的TypeError:this.showContentList不是XMLHttpRequest.xhr.onreadystatechange上的函数 下面的代码

class XhrRequest{
    constructor(_sendQuery, _mainLinkData){
        this.sendQuery = _sendQuery;
        this.mainLinkData = _mainLinkData;
    };

    sendRequest(){
        xhr.open("POST", "connection/query.php", true);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        // send the data-category value in the query
        xhr.send(this.sendQuery);
    };

    showSubMenu(){
        this.sendRequest();
        xhr.onreadystatechange = function(){
            if(this.readyState == 4 && this.status == 200){
                // convert result to object
                let data = JSON.parse(this.responseText);
                const ul = document.createElement('ul');
                let outputBody = "";
                let i = 0;
                for(i in data){
                    // remove the all the white spaces
                    let dataSubCat = data[i].subCategory.replace(" ", "");

                    dataSubCat = dataSubCat.replace("-", "");

                    let subCategoryNoHyphen = data[i].subCategory.replace("-", " ");

                    outputBody += ` <li>
                                        <a href="#">${subCategoryNoHyphen}</a>
                                    </li>`;
                };

                ul.innerHTML = outputBody;

                subMenu.append(ul);
                subMenu.style.opacity = "1";


                this.showContentList();
            };
        };

    };

    showContentList(){
        const subMenuLinks = **strong text**document.querySelectorAll('.sub-link');
        this.sendQuery = "query";
        console.log(this.sendQuery);
        console.log(subMenuLinks);
    };
};

0 个答案:

没有答案