ajax GET 类型不将数据传递给烧瓶

时间:2021-06-15 10:49:11

标签: python jquery ajax flask

我有一个方法尝试使用 GET 方法将变量传递给烧瓶。这是jquery和flask的代码:

<!DOCTYPE html>
<html lang="en">
  <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" />
    <style>
      *,
      body {
        margin: 0;
        padding: 0;
      }
      body {
        padding: 10px; /* IGNORED */
      }
      h2 {
        font-family: "Arial", "Arial Bold", Gadget, sans-serif;
        font-size: 20px;
        font-style: normal;
        font-variant: normal;
        font-weight: 700;
        line-height: 26.4px;
      }
      p,
      a {
        font-family: "Arial", sans-serif;
        font-size: 14px;
        font-style: normal;
        font-variant: normal;
        font-weight: 400;
        line-height: 20px;
      }
      a {
        color: slategray;
        text-decoration: none;
      }
      hr {
        height: 1px;
        margin: 10px 0px; /* IGNORED */
        border: none;
        background-color: silver;
      }
      header {
        border-bottom: 1px solid silver;
        padding: 10px;  /* IGNORED */
      }
      main {
        padding: 20px;  /* IGNORED */
      }
      footer {
        border-top: 1px solid silver;
        padding: 10px;  /* IGNORED */
      }
      footer p {
        font-size: 11px;
        margin: 3px 0px;
        color: silver;
      }
      footer a {
        font-size: 11px;
      }
    </style>
  </head>

  <body bgcolor="white">
    <header>
      <img
        src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/3b/The_Boring_Company_Logo.svg/1024px-The_Boring_Company_Logo.svg.png"
        height="50px"
        alt="TBC"
      />
    </header>

    <main>
      <h2>Hi, Emma</h2>
      <br />
      <p>We welcome you to our platform, ...</p>
      <br />
      <p>
        Are you ready to start a new path in your life with our service? ...
      </p>
      <br />
      <br />
      <p>All the best,</p>
      <p>The Boring Company.</p>
    </main>

    <footer>
      <p>Please do not reply to this email. ...</p>
      <p><a href="#">OC</a> | &copy; All rights reserved</p>
    </footer>
  </body>
</html>

其中 login_bool 是真还是假。

和烧瓶:

    <!-- https://mvnrepository.com/artifact/com.appnexus.grafana-client/grafana-api-java-client -->
<dependency>
    <groupId>com.appnexus.grafana-client</groupId>
    <artifactId>grafana-api-java-client</artifactId>
    <version>1.0.5</version>
</dependency>
     

我在打印(数据)上得到“无”,而如果我在 ajax 上做 POST 而不是默认的 GET,我会得到我需要的正确数据。这可能发生的任何原因?我希望得到一些见解,非常感谢。

1 个答案:

答案 0 :(得分:-1)

你还没有在ajax调用中定义方法类型。

$.ajax({
        type:"GET",
        url: "{{ url_for('impact') }}",
        contentType: "application/json",
        data: JSON.stringify(login_bool),
        dataType: "json",
        success: function(response) {
            console.log(response);
        },
        error: function(err) {
            console.log(err);
        }
      });