Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First you need a function to actually do the polling. When a response is received, you'll update the progress bar and do whatever else you'd like. Here I have that split out into a separate, unoriginally named function, <code>parseResponse()</code>, which then calls <code>poll()</code> again until the job is done.</p> <pre><code>var jobId = 12345; function poll() { setTimeout(function() { $.ajax({ url: 'https://app.zencoder.com/api/v2/jobs/' + jobId + '/progress', type: 'GET', headers: { "Zencoder-Api-Key": 'ZENCODER READ ONLY API KEY' }, //dataType: 'json', success: function(data) { parseResponse(data); }, error: function(data) { console.log(data) } }); }, 3000); } </code></pre> <p>When we get the progress back from Zencoder, we only want to update the progress bar when the job is in certain states. Here we just log out the state unless it's processing or finished, in which case we do indeed change the width of the progress bar.</p> <pre><code>function parseResponse(data) { switch(data.state) { case 'pending': console.log('Pending'); poll(); break; case 'waiting': console.log('Waiting'); poll(); break; case 'processing': console.log('processing'); $('.progress .bar').css('width', Math.round(data.progress) + '%'); poll(); break; case 'finished': console.log('Finished'); $('.progress').removeClass('active'); $('.progress .bar').css('width', '100%'); break; case 'failed': console.log('Failed'); break; case 'cancelled': console.log('Cancelled'); break; default: console.log("Wat?"); } } </code></pre> <p>Once you have this set up, you can kick off the process by calling <code>poll()</code>.</p> <p>This assumes you're using jQuery and only have one progress bar on the page, but that should give you an idea of how to get started.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload