The code below isn't working for me. What did I do wrong? The ajax realtime updating doesn't work even though I used the code one of your coworkers suggested here..
https://groups.google.com/forum/#!searchin/pdfnet-webviewer/ajax$20polling/pdfnet-webviewer/_QeJeSPVpeY/La31QAOL6vsJThis is my code below...
<script type='text/javascript'>
$(function() {
var viewerElement = document.getElementById('viewer');
var myWebViewer = new PDFTron.WebViewer({
type: 'html5',
mobileRedirect: false,
documentId: '$x',
cloudApiId: '$x2',
path: '/lib',
config: '/lib/config.js',
serverUrl: '/lib/html5/annotationHandler.php',
enableAnnotations: true,
streaming: false,
showToolbarControl: true,
}, viewerElement);
$(viewerElement).bind('documentLoaded', function(event){
setInterval(function(){
var am = me.docViewer.GetAnnotationManager();
var clientAnnotData= am.GetAnnotCommand();
$.ajax({
url: serverurl
cache: false,
data : clientAnnotData,
success: function(data) {
//server returned some annotation commands
if (data !== null) {
am.ImportAnnotCommand(data);
}
},
error: function() {
//server gave an error
},
dataType: 'xml'
});
},3000); //execute this code every 3 seconds
});
});
</script>";
I also put just this portion below in my config file in a documentLoaded event function and it still didn't work...
$(viewerElement).bind('
documentLoaded', function(event){
setInterval(function(){
var am = me.docViewer.GetAnnotationManager();
var clientAnnotData= am.GetAnnotCommand();
$.ajax({
url: serverurl
cache: false,
data : clientAnnotData,
success: function(data) {
//server returned some annotation commands
if (data !== null) {
am.ImportAnnotCommand(data);
}
},
error: function() {
//server gave an error
},
dataType: 'xml'
});
},3000); //execute this code every 3 seconds
});
I am not the best with AJAX so in your reply please just make this simple for me to understand why this isn't working and paste the code that will work. This is crucial for my application to work. It seems so simple but I don't understand what I am missing.