fetch api javascript返回html代码

时间:2018-06-07 08:23:18

标签: javascript fetch-api

现在我不知道为什么会发生这种情况,而fetch的功能正在我正在定位的网址上正确显示promises响应。但现在我在console日志中看到的只是一个登录页面的HTML代码,我没有改变任何东西,但为什么会发生这种情况?

const caseform = _doc.forms.namedItem('caseform');

    caseform.addEventListener("submit", e => {
        e.preventDefault();

        this._action = caseform["action"];
        this._method = caseform["method"];

        this._fd = new FormData(caseform);

        async function savecase() {
            this._params = {method: this._method, body: this._fd};
            this._response = await fetch(this._action, this._params);

            try {
                if(this._response.ok) {
                    return await this._response.text();
                }
            } catch(error) {
                return error;
            }
        }

        savecase()
            .then(result => {
                if(result === 'error_in_retention_requirements') {
                    _doc.querySelector('div[data-result-case-error]').style.display = 'block';
                    _doc.querySelector('div[data-result-case-error]').innerHTML = 'Please provide all rentention requirements.';
                    _doc.querySelector('div[data-result-case-error]').scrollIntoView();
                } else if(result === 'error_in_clearance_requirements') {
                    _doc.querySelector('div[data-result-case-error]').style.display = 'block';
                    _doc.querySelector('div[data-result-case-error]').innerHTML = 'Please provide all clearance requirements.';
                    _doc.querySelector('div[data-result-case-error]').scrollIntoView();
                }  else if(result === 'error_in_clearance_requirements') {
                    _doc.querySelector('div[data-result-case-error]').style.display = 'block';
                    _doc.querySelector('div[data-result-case-error]').innerHTML = 'Please provide all clearance requirements.';
                    _doc.querySelector('div[data-result-case-error]').scrollIntoView();
                } else {
                    console.log(result);
                }
            });
    });

这是在控制台日志中返回的返回文本

newcase:136

<!DOCTYPE html>
<html class="no-js" lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>v1.0</title>
    <link rel="icon" href="http://localhost/itd_project/darsystem_v1.0/public/files/img/logo.jpg" type="image/gif" sizes="16x16">
    <link rel="stylesheet" href="http://localhost/itd_project/darsystem_v1.0/public/files/foundation/css/foundation.css">
    <link rel="stylesheet" href="http://localhost/itd_project/darsystem_v1.0/public/files/foundation/css/app.css">
  </head>
  <body>

<script>
const _w = window;
const _doc = document;

_w.onload = () => {
    const pcode = _doc.querySelector('input[type="password"]');

    pcode.onpaste = (e) => {
        e.preventDefault();
    }
}</script>


    <div class="row-login">
        <form action="http://localhost/itd_project/darsystem_v1.0/login/check/?attempt=1&amp;for=dXNlcl9sb2dpbg==" method="post" class="stacked" style="color: #272822; ">
            <div class="row stacked">
                <img class="logo-login" src="http://localhost/itd_project/darsystem_v1.0/public/files/img/logo.jpg"/>
                <h5 class="text-center" style="color: #000000; font-size: 12px;">Department of Agrarian Reform</h5>
            </div>
            <label>ID
                <input type="text" name="username" placeholder="ID Number" />
            </label>
            <label>Password 
                <input type="password" name="password" placeholder="&#9679;&#9679;&#9679;&#9679;&#9679;&#9679;&#9679;&#9679;" autocomplete="off" />
            </label>
            <p>
                <button type="submit" class="dar_login button expanded" style=" color: #fff; box-shadow: 0 2px 4px rgba(10, 10, 10, 0.4);">Log in</button>
            </p>
        </form>
    </div>

<footer style="margin-top: 120px;">
      <p class="footer">&copy; 2018</p>
</footer>
  </body>
</html>

0 个答案:

没有答案