简体   繁体   中英

How to show pdf in a modal window using ajax?

I want to show the pdf inside the modal window using ajax, The url I am calling is sending response type as "application/pdf" , when I show the http.responseText into the modal div, it shows some unreadable text.

>>> endobj 15 0 obj <> endobj 16 0 obj <>/ProcSet[/PDF/Text/ImageC]/XObject<>>>/Rotate 0/Type/Page>> endobj 17 0 obj <>stream h޴ mo rǿ y |& I $ "No . M8 a+ͷ 7C Vd7 r \\ p8 3 a; z[= v R? - 8 mEtB: N :q ԩ 괦' u; / ⻫ ~ ~~>|~ { ^= ~ ǯ y ?zt ͫ 7 m w . O ᷙp} 葦 ۛ Wo gO _ ~ ~{ Ͼ| ꧫ / u 3 } E R W7 M__ n- W> 7/.~{ W mv˶m 7 ^ .y >t R 0 _ . o | ? ysu 엋 z y\\< |q ˗? :lOo ~ aċ~}eS Wo. sn b[ S + } _ /__, ^< Q; ᑧ tz @t m v l ͞ .0 a v -b z ."K;7 6=Z = 8 G ! 9 Ɓ 6 z C W X ( i x Ck~ m [ U KaN> Re4 u 2^f @8֪ & E \\m b н/ދ D ~ 1^r:j= I, fJ &ę 82 ǃ a ` Q 9 {fa :q{(j @q c SD {@ f ) uHeϥX d= ;D &p s 9 !zN KT aG T' " 1ky 2 І( W- ^ 'b A廒 i # Ў i? 6\\ \\ c sz : V ut . $ 4 9ݏ f B Dw Yp ^! J & i !/ p 1 [L C1 E [6B j R ÑlӯF (u l 0 \\

You're not going to get text by returning the pdf, you have to have a program that will interpret that data, which is normally the pdf reader plugin that most modern browsers are equipped with.

Use an iframe in your modal:

<div class="modal">
    <iframe src="/url-to-pdf"></iframe>
</div>

This is a rough example, but you get the idea. If this is embedded in your html, the iframe will be loaded automatically, so you may want to choose when to invoke it via javascript.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM