【问题标题】:XMLHttpRequest state never goes to DONEXMLHttpRequest 状态永远不会变为 DONE
【发布时间】:2019-02-05 17:10:02
【问题描述】:

我得到了这个 mvc 核心应用程序。它的一种方法看起来像这样(现在)

    public IActionResult Call(string call)
    {
        Response.ContentType = "text/plain";
        return Ok (call);
    }

浏览器中的 javascript 看起来像这样

        var xhttp = new XMLHttpRequest();
        xhttp.withCredentials = true;
        xhttp.open("GET", request, true);
        xhttp.onreadystatechange = function ()
        {
            if (this.readyState == 4)
            {
                if (this.status == 200)
                {
                    SetAnswerText(this.responseText);
                }
                else
                {
                    SetApiCallTextAreaValue("request - \n" + request + "\n failed; status = " + this.status);
                }
            }
            else
            {
                SetApiCallTextAreaValue("current status is " + this.readyState + "\n" + this.responseText);
            }
        }

由于某种原因,我只收到 readystate==3(LOADING) 的通知,而我从未收到过 readystate==4(DONE) 的通知。

你能帮我弄清楚为什么会这样吗?

顺便说一句,如果我在浏览器中打开此 Call 方法的 URL,例如 https://..../Call/?call=123,它绝对可以正常工作..

【问题讨论】:

  • 如果您的问题是一个基本的拼写错误,您应该删除您的问题,因为它太窄,对其他用户没有帮助。
  • 您应该添加其他事件(请参阅here)以获得更多信息。

标签: javascript html ajax model-view-controller


【解决方案1】:

omg.. 忘记将函数名称从 SetAnswerText 更改为 SetApiCallTextAreaValue.. 还要多睡。。 仅当我在浏览器中查看代码时才发现错误:P

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-27
    • 1970-01-01
    • 1970-01-01
    • 2013-11-15
    • 1970-01-01
    相关资源
    最近更新 更多