I am trying to send an AJAX request to login. Yesterday it was working perfectly but today when I send a request it sends one request perfectly but a second is unwanted. I'm stuck how to deal with this. Please help.
$('#login_form').submit(function(e) {
e.preventDefault();
$.post("<?php echo base_url() ?>login/login_user",
$(this).serializeArray(),
function(data) {
if (data == 0) {
$(".user").show().delay(2000).fadeOut();
}
if (data == "Epass") {
$(".pass").show().delay(2000).fadeOut();
}
if (data == "admin" || data =="other") {
$(".success").show().delay(2000).fadeOut();
if (data == "admin") {
window.location.href = "<?php echo base_url() ?>dashboard";
} else {
window.location.href = "<?php echo base_url() ?>index";
}
};
});
})
如果需要在浏览器传递给其他代码之前完成该ajax请求,则将asynchronous
设置为false
。
$.ajax(... async: false ...);
I think the following part of your code is causing you the 2nd call
if (data == "admin") {
window.location.href = "<?php echo base_url() ?>dashboard";
} else {
window.location.href = "<?php echo base_url() ?>index";
}
Try (with semi-colon ';' at the end of the PHP echo call):
if (data == "admin") {
window.location.href = "<?php echo base_url(); ?>dashboard";
} else {
window.location.href = "<?php echo base_url(); ?>index";
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.