Note that there are some explanatory texts on larger screens.

plurals
  1. POTaking a photo using Cordova via Backbone.js View
    text
    copied!<p>I am trying to take a photo using the Cordova API (in IBM Worklight) but the success callback never seems to fire (when I use the same code outside of Backbone.js it works perfectly).</p> <p>This is my view file:</p> <pre><code>var app = app || {}; app.WalletView = Backbone.View.extend({ el: '#page', template: Handlebars.getTemplate( 'wallet' ), events: { 'click #camera-snap': 'getPhoto' }, initialize: function() { this.render(); }, // render library by rendering each book in its collection render: function() { this.$el.html( this.template() ); return this; }, getPhoto: function(e) { var $img = this.$el.find('img#camera-image'); console.info('Taking Photo'); /* | BASED ON: http://stackoverflow.com/a/11928792/633056 */ navigator.camera.getPicture( function(data) { $img.show(); alert(data); // &lt;-- success alert //img.src = "data:image/jpeg;base64," + data; $img.attr('src', "data:image/jpeg;base64," + data); $('#camera-status').text("Success"); }, function(e) { console.log("Error getting picture: " + e); $('camera-status').innerHTML = e; //dom.byId('camera-image').style.display = "none"; }, // must be DATA_URL to return the data for future use {quality: 50, destinationType: navigator.camera.DestinationType.DATA_URL, sourceType : navigator.camera.PictureSourceType.CAMERA} ); } }); </code></pre> <p>This is how I initiate that view:</p> <pre><code>'showWallet': function() { new app.WalletView(); }, </code></pre> <p>This is the HTML template:</p> <pre><code>&lt;h1&gt;Camera POC&lt;/h1&gt; &lt;p&gt;Camera Status: &lt;i id="camera-status"&gt;&lt;/i&gt;&lt;/p&gt; &lt;input type="submit" value="Take Picture" id="camera-snap"&gt; &lt;img src="" id="camera-image" style="width: 80%;"&gt; </code></pre> <p>Clicking on the <code>input#camera-snap</code> button brings up the native camera interface. I can then take a photo and (on Android) click the tick button (in the native interface). However, when I am returned to the Hybrid app nothing happens.</p> <p>I would expect the <code>alert()</code> in my success callback to popup with with a huge string of BASE64 data (as it does when not within Backbone.</p> <p>What am I doing wrong?</p>
 

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