javascriptpostfilepicker.io

Javascript blocking on post request


I have, what I believe to be a pretty normal and sane javascript function, below:

$scope.pickFile = function() {
    filepicker.setKey("...");
    filepicker.pick(
        {},
        function(Blob) {  // OnSuccess
            var uuid = Blob.url.split('/').slice(-1)[0];
            window.location.replace("/url" + uuid);
            $.post(
                "/other_url" + uuid,
                {'input': $('#rawText')[0].checked? "text" : "features"}
            );
    });
}

Now, the bizarre thing is that the redirect doesn't happen until the post request finishes. My gut says this might be some magic happening behind the scenes with filepicker, but I have no idea what it might be, and there doesn't seem to be any documentation around it.

It doesn't seem to be simple synchronicity either since the redirect is actually first, but it is blocking on the post request completing.


Solution

  • Try to change the post to explicitly not include the callback handler:

    var mypost = $.ajax({
      type: "POST",
      url:  "/other_url" + uuid,
      data:  {'input': $('#rawText')[0].checked? "text" : "features"}
    });
    return false;