发送表单的GET而不是POST的HTML表单 [英] html form sending GET instead of POST on form submit
问题描述
请原谅我的网络技能,但我有一个非常基本的问题.
Pardon my web skills but i have a very rudimentary problem.
我有这个html表单,理想情况下应该用post调用我的/login url,但是由于某种原因,它总是向该url发送一个get请求,但失败.我不知道这是怎么回事.
I have this html form which should ideally call my /login url with post but for some reason it always sends a get request to that url and fails. I can't figure out how that is happening.
这是我的html表单
<!DOCTYPE html>
<html class="no-js">
<head>
<title>Login - MobileMedic</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="">
<meta name="author" content="" />
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,800italic,400,600,800" type="text/css">
<link rel="stylesheet" href="./css/font-awesome.min.css" type="text/css" />
<link rel="stylesheet" href="./css/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="./css/jquery-ui-1.9.2.custom.min.css" type="text/css" />
<link rel="stylesheet" href="./css/App.css" type="text/css" />
<link rel="stylesheet" href="./css/Login.css" type="text/css" />
<link rel="stylesheet" href="./css/custom.css" type="text/css" />
<script src="./js/jquery-1.9.1.min.js"></script>
<script src="./js/alert.js"></script>
<script src="./js/jquery-ui-1.9.2.custom.min.js"></script>
<script src="./js/bootstrap.min.js"></script>
<script src="./js/plugins/parsley/parsley.js"></script>
</head>
<body>
<div class="gifload"></div>
<div id="login-container">
<div id="logo">
<a href="./index.html"> <img src="./images/logos/logo-login.png" alt="Logo" /> </a>
</div>
<div id="login">
<h3>Welcome to Apprick Technologies.</h3>
<h5>Please sign in to get access.</h5>
<form method="post" action="/login" id="login-form" class="form parsley-form" data-validate="parsley">
<div class="form-group">
<input type="email" class="form-control" id="email" placeholder="Email" required="required">
</div>
<div class="form-group">
<input type="password" class="form-control" id="password" placeholder="Password" required="required">
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary btn-block" name= "Signin" value="Signin"/>
</div>
</form>
</div>
</div>
<!-- /#login-container -->
</body>
为了使问题更清楚,我在parse.com中使用express js,这是定义的两个路由
To make the question more clear i use express js with parse.com and here are the two routing defined
app.get('/login', function(req, res) {
res.send('get is called');
});
app.post('/login', function(req, res) {
res.send('post is called');
});
现在,无论我在表单方法中提供什么,在提交按钮时,我总是在浏览器中得到被调用".
Now no matter what i provide in my form method i always get "get is called" in the browser on submitting the button.
我还尝试调试开发者控制台正在发生的事情,这就是我所得到的
I also tried to debug what is happening in by the developer console and this is what i get
推荐答案
我尝试了您的代码,它正在作为"POST"请求运行.尝试将您的请求更改为"GET",您会在URL中注意到它的末尾是?Signin = Signin" .
I tried your code and it is working as a "POST" request. Try changing your request to "GET" and you can notice in the URL that it has something like this at the end "?Signin=Signin".
在输入标签中添加名称"属性.
Include a "name" attribute to your input tags.
示例:
<input type="email" name="email" class="form-control" id="email" placeholder="Email" required="required">
提交表单后,您会看到类似的内容:
And you can see something like this upon submitting the form:
/login?email=testemail%40test.test&Signin=Signin
这篇关于发送表单的GET而不是POST的HTML表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!