image - Send a picture using cordova on android -
i having problems apache cordova , android. have code send 1 picture server, android cellphone, doesn't work. have tested ajax , php code on server, , works, when try cellphone not.
app.js:
var picturesource; // picture source var destinationtype; // sets format of returned value var image = ""; document.addeventlistener("deviceready", ondeviceready, false); function ondeviceready() { picturesource = navigator.camera.picturesourcetype; destinationtype = navigator.camera.destinationtype; } function capturephoto() { navigator.camera.getpicture(onphotodatasuccess, onfail, { quality: 50, destinationtype: destinationtype.data_url }); } function onphotodatasuccess(imagedata) { var smallimage = document.getelementbyid('smallimage'); smallimage.style.display = 'block'; smallimage.src = "data:image/jpeg;base64," + imagedata; image = "data:image/jpeg;base64," + imagedata; } function onfail(message) { alert('failed because: ' + message); } function submitfunction() { var datastring = 'image='+encodeuricomponent(image); $.ajax({ type: "post", url: "//192.0.1.2/testing/test.php", data: datastring, cache: false, error: function(){ showstatus( "ajax - error()" ); document.getelementbyid("result").innerhtml = 'error'; }, beforesend: function() { document.getelementbyid("result").innerhtml = 'enviando data'; }, success: function(result){ document.getelementbyid("result").innerhtml = result; } }); }
test.php:
<?php header('access-control-allow-origin: *'); require'connection.php'; $mysqli = conectarse(); $res = $mysqli->query("insert imagenes (image) values ('".$_post['image']."')"); $mysqli->query($res); if (!$res) { printf("errormessage: %sn", $mysqli->error); } ?>
this code has following dependencies:
- cordova.js
- jquery.min.js
Comments
Post a Comment