嗨! 我做了一个必须在我的快递服务器上提交的表格,但是我没有得到任何结果,只是错误!怎么做? 这是表单代码和jquery代码。
HTML代码:
<div class="login-form">
<form class="form">
<div class="avatar">
<img src="images/logo_pfe.png" alt="Logo entreprise">
</div>
<h2 class="text-center">Connectez vous !</h2>
<div class="form-group">
<input type="email" id="login" class="form-control" name="username" placeholder="Login" required="required">
</div>
<div class="form-group">
<input type="password" id="password" class="form-control" name="password" placeholder="Mot de password" required="required">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-lg btn-block">Se connecter</button>
</div>
</form>
`
Voici le code jquery qui recupere les infos du Formulaire pour soumettre JavaScript代码
const API_URL = 'localhost:3001';
const AUTH_URL = `${API_URL}/auth`;
$(() => {
$('form').submit((event) => {
event.preventDefault();
const email = $('#login').val();
const password = $('#password').val();
let user = {
email,
password
};
login(user)
});
function login(user) {
$.ajax({
url: `${AUTH_URL}/login`,
type: 'post',
success: function (data) {
console.log(data);
},
error: function (error) {
console.log(error);
}
});
}
});
当我提交表单时,控制台中返回给我的内容 console.log()
abort: abort()
always: function always()
catch: function catch()
done: function add()
fail: function add()
getAllResponseHeaders: function getAllResponseHeaders()
getResponseHeader: function getResponseHeader()
overrideMimeType: function overrideMimeType()
pipe: function pipe()
progress: function add()
promise: function promise()
readyState: 0
setRequestHeader: function setRequestHeader()
state: function state()
status: 0
statusCode: function statusCode()
statusText: "error"
then: function then()
<prototype>: Object { … }
connexion.js:37:25