Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daksamedia/13c42ba830ab821f879c4a226f9365e8 to your computer and use it in GitHub Desktop.
Save daksamedia/13c42ba830ab821f879c4a226f9365e8 to your computer and use it in GitHub Desktop.
Cordova Camera Plugin cordova-plugin-camera upload jquery ajax to server request
<!DOCTYPE html>
<!-- Aysad Kozanoglu -->
<html>
<head>
<title>foto cek</title>
<style>
html {
-webkit-user-select: none;
}
</style>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;" />
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
var pictureSource; // picture source
var destinationType; // sets the format of returned value
// Wait for device API libraries to load
//
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// device APIs are available
//
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
// Called when a photo is successfully retrieved
//
function onPhotoDataSuccess(imageData) {
var smallImage = document.getElementById('smallImage');
smallImage.style.display = 'block';
smallImage.src = "data:image/jpeg;base64," + imageData;
fotoUpload(imageData);
}
// A button will call this function
//
function capturePhotoEdit() {
// Take picture using device camera, allow edit, and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true,
destinationType: destinationType.DATA_URL });
}
// Called if something bad happens.
//
function onFail(message) {
alert('Failed because: ' + message);
}
</script>
</head>
<body onload="onLoad()">
<center>
<img src="logo.png" width="50%" border=0>
<br>
<h1>Entwicklungsumgebung</h1>
<br>
Kamera Photoschuss und upload Server
<br><br><br><br>
<button onclick="capturePhotoEdit();" style="height:60px;width:80%">Photo Schnappschuss</button>
<br><br><br>
<a href="http://5.45.96.121/upload/" target ="_blank"> <h2>Bilder auf dem Server ansehen </h2></a>
<br><br><br>
<div id="ajaxStatus"></div>
<img style="display:none;width:50%" id="smallImage" src="" />
<br><br><font size="-2"> Erfinder: Levent Yakar <br> Architekt: Aysad Kozanoglu
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$("#ajaxStatus").html("ein Bild aufnehmen");
});
function fotoUpload(imageData){
//alert(imageData);
$.ajax({
type: "POST",
url: "http://5.45.96.121/upload/up2.php",
data: { img_data:imageData},
cache: false,
contentType: "application/x-www-form-urlencoded",
success: function (result) {
alert("upload OK: "+ result);
}
});
$("#ajaxStatus").html("bild hochgeladen");
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment