使用javascript和postgresq登录

2024-03-29 10:22:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我的登录功能有问题。代码运行良好,没有错误,等等。我的问题是,当我尝试登录,它不会重定向到下一个html页面,只是在屏幕上登录.html但是当我输入用户名和密码时,它会说“好”。下面是我的密码。你知道吗

@app.route('/login', methods=['POST'])
@auth.login_required
def login():
params = request.get_json()

res = spcall('login', (params['username'], params['pass']))
print(str(res[0][0]))
if 'Error' in str(res[0][0]):
    return jsonify(status='error', url='login.html')

return jsonify(status='success', url='restaurant.html')

js公司:

function login(){
$.ajax(
{
  url: 'http://127.0.0.1:5000/login',
  contentType: 'application/json; charset=utf-8',
  data: JSON.stringify({
      'username': $("#username").val(),
      'pass': $("#pass").val()
  }),
  type: "POST",
  dataType: "json",
  error: function (e) {
      alert('Something Went Wrong!!');
  },
  success: function (response) {
      window.location = response.url;
  },
  beforeSend: function(xhrObj){
      xhrObj.setRequestHeader("Authorization",
            "Basic " + btoa("ako:default"));
  }

  });

}

html格式:

<div id="login">
    <form>
        <h2> Login </h2>
        <input type="text" id="username" placeholder="Username" />
        <input type="password" id="pass" placeholder="Password" />
        <input type="submit" onclick="login();" id="login-btn" value="Login" />
    </form>
</div>
<script src="app.js"></script>
<script src="jQuery-2.1.4.min.js"></script>

Tags: idjsonurl密码inputhtmltypejs