The following code is giving false result all the time. I think i am comparing two numeric variables. is that not so?
var request; var getfilesize; var maxdisplaysize=2097152;
request = $.ajax({
type: "HEAD",
url: getfile,
success: function () {
getfilesize = request.getResponseHeader("Content-Length");
console.log("Size is" + getfilesize+'xxx');
}
});
parseInt( getfilesize, 10 );
if ( getfilesize < maxdisplaysize ) {
$("#displayfile").load(getfile);
console.log('file size less then 2mb 2097152bytes');
} else {
$("#displayfile").append('<p>sorry large file<p>');
}
Pl advice why the if condition is always evaluating to be false?
Your call to
parseInt()has no effect, as you don’t do anything with the result.is what you want. The
parseInt()function does not (and cannot) modify the first parameter.Now, that said, the next problem you’re going to want to deal with is the fact that your ajax call is asynchronous. You need to put that code that uses the file size inside the “success” callback.