我之前使用过ajax,但这次ajax没有传递参数,我已经尝试了一些解决方案,但无法解决这个问题。
的jQuery
$('.entrar').click(function(){
event.preventDefault();
if (check_login()){
var dataLogin;
var manter_ligado;
if ($('#mantem_login').is(':checked'))
{
manter_ligado = "1";
} else {
manter_ligado = "0";
}
dataLogin = 'mail=' + $('#login_mail').val() + '&pass=' + $('#login_password').val() + '&on=' + manter_ligado;
$.ajax({
url: 'modules/login.php',
type: 'POST',
//data: dataLogin,
data : ({
mail : $('#login_mail').val(),
pass : $('#login_password').val(),
on : manter_ligado
}),
success: function(data) {
alert('Login efectuado com sucesso.');
console.log(data);
},
error: function(xhr, textStatus, errorThrown) {
alert('Login nao entrou');
console.log(xhr.statusText);
console.log(textStatus);
console.log(error);
}
});
return false;
}
})
这是HTML
<span class="title">Entrar na sua conta</span>
<input name="login_mail" placeholder=" e-mail" id="login_mail" type="email" class="email text_box"/>
<input name="login_password" placeholder="password" id="login_password" type="password" class="password text_box" />
<span>Perdeu a password?</span>
<div class="mantem_login">
<input name="mantem_login" id="mantem_login" type="checkbox" class="mantem_login" />
<label for="mantem_login"><span class="mantem_login">Manter-me conectado</span></label>
</div>
<input type="submit" name="entrar" class="submit_button entrar" id="entrar" value="" />
</div>
</form>
我可以做什么让参数到达网址?
答案 0 :(得分:-1)
从参数值中删除圆括号:
data: {
mail : $('#login_mail').val(),
pass : $('#login_password').val(),
on : manter_ligado
}