XMLHttpRequest to open PDF in browser

后端 未结 3 1948
庸人自扰
庸人自扰 2020-12-07 03:36

I want to do XMLHttpRequest and then open a PDF in the Browser by sending the filename by POST method.

   xmlhttp.open(\"POST\",\"pdf.php\",true); //CHANGE
          


        
3条回答
  •  独厮守ぢ
    2020-12-07 04:27

    If you're opening the PDF in the same window there's no point in using an XmlHttpRequest, just set window.location (window.location.assign("http://example.com/location/file.pdf"), window.location.href="http://etc) from your javascript, instead of invoking XmlHttpRequest. (if you've received the PDF bytes from the XmlHttpRequest how are you going to convince the browser to display it with PdfPluginX anyway?)

    If you want the PDF in a new browser window just use window.open(...) directly from your javascript.

提交回复
热议问题