0

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?

1 Answer 1

4

Your call to parseInt() has no effect, as you don't do anything with the result.

getfilesize = parseInt(getfilesize, 10);

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.

Sign up to request clarification or add additional context in comments.

1 Comment

main issue was the async call, putting it inside the async call fixed everything. i do not need to convert now. thx for pointing that!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.