Reputation: 2949
I'm using jquery 1.11.3. I'm trying t use ajaxComplete.It's showing only loading icon without returning error message, only in console. As I've read here:
http://www.w3schools.com/jquery/ajax_ajaxcomplete.asp
Note: As of jQuery version 1.8, this method should only be attached to document.
But how to use it in my case?
My code is:
$(document).ready(function() {
$("#email").change(function() {
var usr = $("#email").val();
if (usr.length >= 3) {
$("#status").html('<img align="absmiddle" src="/images/loader.gif" /> Checking availability...');
$.ajax({
type: "POST",
url: "/check_user.php",
data: "email=" + usr,
success: function(msg) {
$("#status").ajaxComplete(function(event, request, settings) {
if (msg == 'OK') {
$("#email").removeClass('ErrorField'); // if necessary
$("#email").addClass("object_ok");
$(this).html('');
$("#submit").attr("disabled", false);
} else {
$("#email").removeClass('object_ok'); // if necessary
$("#email").addClass("ErrorField");
$(this).html(msg);
$("#submit").attr("disabled", true);
}
});
}
});
} else {
$("#email").removeClass('object_ok'); // if necessary
$("#email").addClass("ErrorField");
}
});
});
Upvotes: 3
Views: 539
Reputation: 167182
You don't need to use AJAX Complete inside an AJAX success
function. Change your code to:
$("#status").html('<img src="/images/loader.gif" /> Checking ...');
$.ajax({
type: "POST",
url: "/check_user.php",
data: "email=" + usr,
success: function(msg) {
// Remove this completely
// $("#status").ajaxComplete(function(event, request, settings) {
if (msg == 'OK') {
$("#email").removeClass('ErrorField');
$("#email").addClass("object_ok");
$(this).html('');
$("#submit").attr("disabled", false);
} else {
$("#email").removeClass('object_ok');
$("#email").addClass("ErrorField");
$(this).html(msg);
$("#submit").attr("disabled", true);
}
});
// And this too.
// }
});
Upvotes: 2