如何在另一个函数内部的函数中返回变量?

时间:2018-06-28 21:13:25

标签: javascript

我必须将此变量作为另一个函数的参数来调用,但由于无法返回,因此似乎无法执行此操作。我该怎么办?

function Getthisvarible()
{
    var thisvariable;
    var Request = new XMLHttpRequest();
    var input = document.getElementById("SearchBox").value;
    var url = "urlstring"

    Request.open("GET",url,true);

    Request.setRequestHeader("Authorization", "Bearer <apikey>");
    Request.setRequestHeader("Accept", "application/vnd.api+json");

    Request.send();

   Request.onreadystatechange = function () {
        if (this.readyState == 4) {
            var jsonparsed = JSON.parse(Request.responseText);
            var thisvariable = jsonparsed.data[0];

        }

    }
    return thisvariable;


}

function Usethisvariable(somevariable)
{}

Usethisvariable(Getthisvariable());

0 个答案:

没有答案