Prompt file download with XMLHttpRequest

后端 未结 3 1928
清歌不尽
清歌不尽 2020-12-08 00:36

I\'m aware that jQuery\'s ajax method cannot handle downloads, and I do not want to add a jQuery plugin to do this.

I want to know how to send POST data with XMLHttp

3条回答
  •  盖世英雄少女心
    2020-12-08 01:13

    XHR request will not trigger file download. I can't find explicit requirement, but W3C doc on XMLHttpRequest doesn't describe any special reaction on content-disposition=attachment responses either

    You could download file by window.open() in separate tab, if it was not POST request. Here it was suggested to use hidden form with target=_blank

    UPD: this answer is not accurate anymore since the introduction of Blob API. Please refer to Steven's answer for details.

提交回复
热议问题