mardi 5 mai 2015

Why form can be used to download file but AJAX cannot?

Given two codes, both trying to trigger server to give back of downloadable file using http header in response i.e. "Content-Disposition", "attachment; filename=filename.ext:

  1. Using form, $('<form></form>').attr('href', path) ... .submit().remove();

  2. Using ajax, $.ajax(url, config);

I would like to know why browsers handle that differently, since form and ajax are not quite different in term of sending request and receiving servers responses. I have search around, but nothing is convincing.

PS: I'm aware of CROS, but in this case cross domain is not an issue here.

Aucun commentaire:

Enregistrer un commentaire