javascript - PDFObject: How to reload container with a different copy of the same file? -


i have button generates pdf, reloads pdf in browser replacing container it's in itself, different link. reason, new pdf doesn't show up, old 1 there still no matter how many times refreshed. i'm not using iframe or object/embed method, i'm using http://pdfobject.com/

my html pdfobject container:

<div id="pdfcontainer">     <div id="pdfsample"></div> </div> 

my javascript initiate src upon window load:

<script type="text/javascript">     $(function () {         pdfobject.embed("myinitialpdf.pdf", "#pdfsample");     }) </script> 

my ajax call pdf-creation/container-refresh:

$('#genpdf').click(function () {     $.ajax({         url: "mergepdf.php",         data: str,         cache: false,         success: function (result) {             $("#pdfobject").attr("src", "newpdf.pdf");             var container = document.getelementbyid("pdfcontainer");             var content = container.innerhtml;             container.innerhtml = content;         }     }); }); 

everytime button id genpdf clicked, new pdf generated name "newpdf.pdf" , container should replace assigned src path new source path of new pdf (which same name before). don't understand if it's cache that's preventing or not. missing something?

you specified cache: false means success: function (result) { passed not-cached result. proceed never use it , instead change src of object was, results of fetching src url cached browser because fetched before. if it's not cached, browser never fetch file again because never perceived change of value in src.

still me?

what add random number end of url it's new url , browser fetch file again because doesnt know if newpdf.pdf?number=random1 or isn't same newpdf.pdf?number=random2. better, can add number know different every time try it, current time in seconds.

here's code again, minor adjustment:

$('#genpdf').click(function () {     $.ajax({         url: "mergepdf.php",         data: str,         cache: false,         success: function (result) {             var t = new date.gettime();             $("#pdfobject").attr("src", "newpdf.pdf?"+t);             var container = document.getelementbyid("pdfcontainer");             var content = container.innerhtml;             container.innerhtml = content;         }     }); }); 

something important i'd add: isn't enough solution, though answers question. better solution generate file named after timestamp (with pdf extension of course) , return result , use in $("#pdfobject").attr("src", result);. make sure clean files named timestamp old, more hour, day or week depending on think right. ensure nobody fighting on filename triggering new pdf creation @ same time, make sure don't have massive archive of obsolete pdf files.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -