download file using an ajax request

后端 未结 12 2358
旧时难觅i
旧时难觅i 2020-11-21 23:46

I want to send an \"ajax download request\" when I click on a button, so I tried in this way:

javascript:

var xhr = new XMLHttpRequest();
xhr.open(\         


        
12条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 00:46

    I prefer location.assign(url);

    Complete syntax example:

    document.location.assign('https://www.urltodocument.com/document.pdf');
    

    developer.mozilla.org/en-US/docs/Web/API/Location.assign

提交回复
热议问题