[英]JQuery / $.ajax /alert in .fail, but it succeed
I have a little problem when i use ajax in JQuery. 我在JQuery中使用Ajax时遇到了一个小问题。 Let me explain: A user enter login, password, name, email, ... and I use a servlet to create the user's account. 让我解释一下:用户输入登录名,密码,名称,电子邮件等,然后我使用servlet创建用户帐户。
$(function(){
$("#subinsc").click(function(){
var nom=$("#nom").val();
var prenom=$("#prenom").val();
var email=$("#email").val();
var login=$("#login").val();
var password1=$("#pass1").val();
var password2=$("#pass2").val();
//verif_form_inscription just check if login and password are ok.
var ok=verif_form_inscription(login,password1,password2);
if(ok){
$.ajax({
type:"get",
async:false,
url: "HERE IS THE CREATEACCOUNT SERVLET",
data: {mail : email,login:login,password:password1,nom:nom,prenom:prenom},
success:function(res){
alert("ok");
$(document).ready(function(){
$("#popup").show(800);
$("#insc").replaceWith(jQuery("#popup"));
});
},
error:function(res){
console.log(res);
alert("fail servlet");
}
})
};
});})
The servlet always "work", the user is in the dataBase , but on the screen I have the .fail alert and not the succeed alert and the #popup div saying "Welcome, your are registred". servlet总是“工作”,用户在数据库中 , 但是在屏幕上,我显示.fail警报,而不显示成功警报,并且#popup div说“欢迎,您已注册”。
Here is the form balise: 这是形式balise:
<form id="insc" method="get" action="">
And the submit balise: 并提交balise:
<input type="submit" value="SIGN UP" id="subinsc"/>
If anyone could help me... Thanks in advance :) 如果有人可以帮助我...在此先感谢:)
EDIT: Solved. 编辑:解决。
You are mixing callback
and deferred
您正在混合callback
和deferred
Either write in this way 用这种方式写
$.ajax({
..,
success:function(){
alert("Ok, succeed");
..
},
error : function(){
alert("Fail createuser");
}
})
OR 要么
$.ajax({
...
})
.done(function() {
alert("succee");
}).fail(function() {
alert("Fail createuser");
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.