2

I tried to do an AJAX request and create download:

$.ajax({
   url: "urlToVerifyRights",
   ...,

    complete: function(){
       location.href = ...
   }
});

Seems is not working in Chrome iOS and Android but in Desktop and Safari ios works

Where is the problem ?

Snake Eyes
  • 16,287
  • 34
  • 113
  • 221
  • When you says "download", do you mean that your location.href links to a downloadable file? Have you tried to change the location.href to an alert or log to check if the problem is there? – Víctor Sep 11 '15 at 07:09
  • I checked, for sure... The url is ok. I tried with small application with a simple `location.href` and it works. With ajax, doesn't work. – Snake Eyes Sep 11 '15 at 07:26

4 Answers4

0

Try with done

$.ajax({
   ...
    ...
}).done(function() {
    location.href = ...
});
Víctor
  • 3,029
  • 3
  • 28
  • 43
0

Modify to this:

$.ajax({
   url: "urlToVerifyRights",
   ...,

    complete: function(){
       location.href = ...
       return false;
   }
});

Related: window.location.href not working

Community
  • 1
  • 1
Víctor
  • 3,029
  • 3
  • 28
  • 43
0

One last try, now with promises:

doAjax: function () {

  var deferredValue = $.Deferred(),

  $.ajax({
     url: "urlToVerifyRights",
     ...,

      complete: function(){

         deferredValue.resolve();
    }
  });

  return deferredValue.promise();

}

doAjax ()
  .then(function () {
     location.href = ...

  })
Víctor
  • 3,029
  • 3
  • 28
  • 43
0

I solved issue with the following workaround:

// I mean complete from $.ajax

complete: function(){
          var $form = $("<form>");
          $form.prop("method", "POST");
          $form.prop("action", "urlToDownload");
          $form.prop("id", "test");
          $form.append($("<input type='hidden' value='aValue' name='inputName' />"));

          $("body").append($form);
          $form.submit();
}

and that's works. I don't know why, but works.

Snake Eyes
  • 16,287
  • 34
  • 113
  • 221