if statement doesn't work in Jquery Ajax call?
I used if state开发者_JAVA百科ments before in a the success function of an ajax call but for the life of me I can't get this to work. I can alert all VARS and they show the data, but the condition statement will not work. What am I doing wrong? I just can't get it.
jQuery.ajax({
type: "POST",
url: "/ajax/uiProcessPhoto.php",
data: "action="+ action,
success: function(response){
var s_response = response.split("|");
var qsize = data.fileCount;
var ptotal = s_response[0];
var ltotal = s_response[1];
var allowed = s_response[1] - s_response[0];
if (ptotal >= ltotal){
alert("Unable to add photos to queue. You have reached the maximum number of photo uploads allowed.");
}else if (ptotal + qsize >= ltotal){
alert("The total photos select will exceed the maximum upload limit. Please upload up to " + allowed + " more photos to continue.");
}else if (response == 1){
jQuery('#upload').show();
};
alert(allowed);
}
});
You're treating ptotal
and qtotal
as strings, not as numbers. Under each the +
in the following line
}else if (ptotal + qsize >= ltotal){
will cause them to be glued together rather than be sum up.
You'd like to parse those strings into real numbers:
var ptotal = parseInt(s_response[0]);
var ltotal = parseInt(s_response[1]);
精彩评论