Javascript 等待结果

问题描述

我这里有一个简单的代码,但目前我没有找到正确的编码方式,你能告诉我我必须如何编码它,函数 ReadCheck() 给我来自服务器的结果,而不仅仅是“未定义” "

function Check()
{
            var xhttp = new XMLHttpRequest();
            var data = { nuser: "username",nemail: "email",};
            
            xhttp.open("POST","api/posts/check",true); 
            xhttp.setRequestHeader("Content-Type","application/json");
            xhttp.onreadystatechange = function()
            {
            if(this.readyState == 4 && this.status == 200)
             {
                return this.responseText;
             }
            }
            xhttp.send(JSON.stringify(data));
}



function ReadCheck()
{
     console.log(Check());
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)