I'm trying to call a javascript function after making a POST request using Jquery $.post()
post request sends base64 image data and writes it down in the server the problem is that the post request is done and the file is uploaded but there is no javascript function called
getCounterNumber(); is not working, the function supposed to do this
function getCounterNumber(Path){
Tesseract.recognize(
Path,
'eng',
{ logger: m => console.log(m) }
).then(({ data: { text } }) => {
window.location.href = "getcounterreading.php?counterNumber="+text+"";
})
}
jQuery crop button click
var base64data = reader.result;
$.post('http://127.0.0.1/counter/uploadcounter.php', {image:base64data},
function(response){
bs_modal.modal('hide');
alert("success upload image");
window.location.href = "uploadcounter.php";
console.log(response);
});
uploadcounter.php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$folderPath = '../../uploads/counters/';
$image_parts = explode(";base64,", $_POST['image']);
$image_type_aux = explode("image/", $image_parts[0]);
$image_type = $image_type_aux[1];
$image_base64 = base64_decode($image_parts[1]);
$file = $folderPath . uniqid() . '.png';
file_put_contents($file, $image_base64);
echo ("image uploaded successfully.");
console.log($file);
echo '<script>getCounterNumber("'.$file.'")</script>';
}
.then()after the POST in the js which waits for the response, grabs the file name, and then callsgetCountNumber.